mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
cpp: added to_lowercase and to_uppercase to SharedString (#6869)
* cpp: added to_lowercase and to_uppercase to SharedString * Update api/cpp/include/slint_string.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update api/cpp/include/slint_string.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update api/cpp/include/slint_string.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update api/cpp/include/slint_string.h Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update internal/core/string.rs Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update internal/core/string.rs Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update internal/core/string.rs Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update internal/core/string.rs Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * code review feedback * Update api/cpp/tests/datastructures.cpp Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * code review feedback * Update api/cpp/include/slint_string.h Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev> * Update api/cpp/include/slint_string.h Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
This commit is contained in:
parent
5f08e09810
commit
6ebce7e5f4
3 changed files with 75 additions and 0 deletions
|
@ -127,6 +127,34 @@ struct SharedString
|
||||||
/// \endcode
|
/// \endcode
|
||||||
static SharedString from_number(double n) { return SharedString(n); }
|
static SharedString from_number(double n) { return SharedString(n); }
|
||||||
|
|
||||||
|
/// Returns the lowercase equivalent of this string, as a new SharedString.
|
||||||
|
///
|
||||||
|
/// For example:
|
||||||
|
/// \code
|
||||||
|
/// auto str = slint::SharedString("Hello");
|
||||||
|
/// auto str2 = str.to_lowercase(); // creates "hello"
|
||||||
|
/// \endcode
|
||||||
|
SharedString to_lowercase() const
|
||||||
|
{
|
||||||
|
auto out = SharedString();
|
||||||
|
cbindgen_private::slint_shared_string_to_lowercase(&out, this);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the uppercase equivalent of this string, as a new SharedString.
|
||||||
|
///
|
||||||
|
/// For example:
|
||||||
|
/// \code
|
||||||
|
/// auto str = slint::SharedString("Hello");
|
||||||
|
/// auto str2 = str.to_uppercase(); // creates "HELLO"
|
||||||
|
/// \endcode
|
||||||
|
SharedString to_uppercase() const
|
||||||
|
{
|
||||||
|
auto out = SharedString();
|
||||||
|
cbindgen_private::slint_shared_string_to_uppercase(&out, this);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if \a a is equal to \a b; otherwise returns false.
|
/// Returns true if \a a is equal to \a b; otherwise returns false.
|
||||||
friend bool operator==(const SharedString &a, const SharedString &b)
|
friend bool operator==(const SharedString &a, const SharedString &b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,17 @@ SCENARIO("SharedString API")
|
||||||
str = "Hello";
|
str = "Hello";
|
||||||
REQUIRE(str.size() == 5);
|
REQUIRE(str.size() == 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("to_lowercase")
|
||||||
|
{
|
||||||
|
str = "Hello";
|
||||||
|
REQUIRE(std::string_view(str.to_lowercase().data()) == "hello");
|
||||||
|
}
|
||||||
|
SECTION("to_uppercase")
|
||||||
|
{
|
||||||
|
str = "Hello";
|
||||||
|
REQUIRE(std::string_view(str.to_uppercase().data()) == "HELLO");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Basic SharedVector API", "[vector]")
|
TEST_CASE("Basic SharedVector API", "[vector]")
|
||||||
|
|
|
@ -474,6 +474,42 @@ pub(crate) mod ffi {
|
||||||
append("!");
|
append("!");
|
||||||
assert_eq!(s.as_str(), "Hello, world!");
|
assert_eq!(s.as_str(), "Hello, world!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn slint_shared_string_to_lowercase(
|
||||||
|
out: &mut SharedString,
|
||||||
|
ss: &SharedString,
|
||||||
|
) {
|
||||||
|
*out = SharedString::from(ss.to_lowercase());
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_slint_shared_string_to_lowercase() {
|
||||||
|
let s = SharedString::from("Hello");
|
||||||
|
let mut out = SharedString::default();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
slint_shared_string_to_lowercase(&mut out, &s);
|
||||||
|
}
|
||||||
|
assert_eq!(out.as_str(), "hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn slint_shared_string_to_uppercase(
|
||||||
|
out: &mut SharedString,
|
||||||
|
ss: &SharedString,
|
||||||
|
) {
|
||||||
|
*out = SharedString::from(ss.to_uppercase());
|
||||||
|
}
|
||||||
|
#[test]
|
||||||
|
fn test_slint_shared_string_to_uppercase() {
|
||||||
|
let s = SharedString::from("Hello");
|
||||||
|
let mut out = SharedString::default();
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
slint_shared_string_to_uppercase(&mut out, &s);
|
||||||
|
}
|
||||||
|
assert_eq!(out.as_str(), "HELLO");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue