mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
Move the string_to_slice
helper into sixtyfps_string.h
for easier editing
This commit is contained in:
parent
3bb4b87bc7
commit
9a8c6bf9f7
2 changed files with 28 additions and 18 deletions
|
@ -111,13 +111,21 @@ struct SharedString
|
||||||
}
|
}
|
||||||
|
|
||||||
friend bool operator<(const SharedString &a, const SharedString &b)
|
friend bool operator<(const SharedString &a, const SharedString &b)
|
||||||
{ return std::string_view(a) < std::string_view(b); }
|
{
|
||||||
|
return std::string_view(a) < std::string_view(b);
|
||||||
|
}
|
||||||
friend bool operator<=(const SharedString &a, const SharedString &b)
|
friend bool operator<=(const SharedString &a, const SharedString &b)
|
||||||
{ return std::string_view(a) <= std::string_view(b); }
|
{
|
||||||
|
return std::string_view(a) <= std::string_view(b);
|
||||||
|
}
|
||||||
friend bool operator>(const SharedString &a, const SharedString &b)
|
friend bool operator>(const SharedString &a, const SharedString &b)
|
||||||
{ return std::string_view(a) > std::string_view(b); }
|
{
|
||||||
|
return std::string_view(a) > std::string_view(b);
|
||||||
|
}
|
||||||
friend bool operator>=(const SharedString &a, const SharedString &b)
|
friend bool operator>=(const SharedString &a, const SharedString &b)
|
||||||
{ return std::string_view(a) >= std::string_view(b); }
|
{
|
||||||
|
return std::string_view(a) >= std::string_view(b);
|
||||||
|
}
|
||||||
|
|
||||||
/// Writes the \a shared_string to the specified \a stream and returns a reference to the
|
/// Writes the \a shared_string to the specified \a stream and returns a reference to the
|
||||||
/// stream.
|
/// stream.
|
||||||
|
@ -126,15 +134,18 @@ struct SharedString
|
||||||
return stream << std::string_view(shared_string);
|
return stream << std::string_view(shared_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend SharedString operator+(const SharedString &a, std::string_view b) {
|
friend SharedString operator+(const SharedString &a, std::string_view b)
|
||||||
|
{
|
||||||
SharedString a2 = a;
|
SharedString a2 = a;
|
||||||
return a2 += b;
|
return a2 += b;
|
||||||
}
|
}
|
||||||
friend SharedString operator+(SharedString &&a, std::string_view b) {
|
friend SharedString operator+(SharedString &&a, std::string_view b)
|
||||||
|
{
|
||||||
a += b;
|
a += b;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
SharedString &operator+=(std::string_view other) {
|
SharedString &operator+=(std::string_view other)
|
||||||
|
{
|
||||||
cbindgen_private::sixtyfps_shared_string_append(this, other.data(), other.size());
|
cbindgen_private::sixtyfps_shared_string_append(this, other.data(), other.size());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -147,4 +158,14 @@ private:
|
||||||
}
|
}
|
||||||
void *inner; // opaque
|
void *inner; // opaque
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace private_api {
|
||||||
|
cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str)
|
||||||
|
{
|
||||||
|
return cbindgen_private::Slice<uint8_t> {
|
||||||
|
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(str.data())), str.size()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,17 +103,6 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let mut string_config = config.clone();
|
let mut string_config = config.clone();
|
||||||
string_config.export.exclude = vec!["SharedString".into()];
|
string_config.export.exclude = vec!["SharedString".into()];
|
||||||
string_config.trailer = Some(
|
|
||||||
"namespace sixtyfps::private_api {
|
|
||||||
cbindgen_private::Slice<uint8_t> string_to_slice(std::string_view str) {
|
|
||||||
return cbindgen_private::Slice<uint8_t> {
|
|
||||||
const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(str.data())),
|
|
||||||
str.size()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}".to_owned(),
|
|
||||||
);
|
|
||||||
|
|
||||||
cbindgen::Builder::new()
|
cbindgen::Builder::new()
|
||||||
.with_config(string_config)
|
.with_config(string_config)
|
||||||
.with_src(crate_dir.join("string.rs"))
|
.with_src(crate_dir.join("string.rs"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue