mirror of
https://gitee.com/openharmony/third_party_rust_cxx
synced 2024-11-24 07:40:19 +00:00
Add rust::Str(const char *, size_t) constructor
This commit is contained in:
parent
c2bbd952d2
commit
894c5e45dc
@ -59,6 +59,7 @@ public:
|
||||
|
||||
Str(const std::string &);
|
||||
Str(const char *);
|
||||
Str(const char *, size_t);
|
||||
Str(std::string &&) = delete;
|
||||
|
||||
Str &operator=(Str) noexcept;
|
||||
|
10
src/cxx.cc
10
src/cxx.cc
@ -106,13 +106,11 @@ Str::Str() noexcept : repr(Repr{reinterpret_cast<const char *>(this), 0}) {}
|
||||
|
||||
Str::Str(const Str &) noexcept = default;
|
||||
|
||||
Str::Str(const std::string &s) : repr(Repr{s.data(), s.length()}) {
|
||||
if (!cxxbridge03$str$valid(this->repr.ptr, this->repr.len)) {
|
||||
panic<std::invalid_argument>("data for rust::Str is not utf-8");
|
||||
}
|
||||
}
|
||||
Str::Str(const std::string &s) : Str(s.data(), s.length()) {}
|
||||
|
||||
Str::Str(const char *s) : repr(Repr{s, std::strlen(s)}) {
|
||||
Str::Str(const char *s) : Str(s, std::strlen(s)) {}
|
||||
|
||||
Str::Str(const char *s, size_t len) : repr(Repr{s, len}) {
|
||||
if (!cxxbridge03$str$valid(this->repr.ptr, this->repr.len)) {
|
||||
panic<std::invalid_argument>("data for rust::Str is not utf-8");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user