@@ -31,8 +31,10 @@ void cxxbridge1$cxx_string$push(std::string &s, const std::uint8_t *ptr,
3131void cxxbridge1$string$new (rust::String *self) noexcept ;
3232void cxxbridge1$string$clone(rust::String *self,
3333 const rust::String &other) noexcept ;
34- bool cxxbridge1$string$from(rust::String *self, const char *ptr,
35- std::size_t len) noexcept ;
34+ bool cxxbridge1$string$from_utf8(rust::String *self, const char *ptr,
35+ std::size_t len) noexcept ;
36+ bool cxxbridge1$string$from_utf16(rust::String *self, const char16_t *ptr,
37+ std::size_t len) noexcept ;
3638void cxxbridge1$string$drop(rust::String *self) noexcept ;
3739const char *cxxbridge1$string$ptr(const rust::String *self) noexcept ;
3840std::size_t cxxbridge1$string$len(const rust::String *self) noexcept ;
@@ -81,11 +83,17 @@ String::String(String &&other) noexcept : repr(other.repr) {
8183String::~String () noexcept { cxxbridge1$string$drop (this ); }
8284
8385static void initString (String *self, const char *s, std::size_t len) {
84- if (!cxxbridge1$string$from (self, s, len)) {
86+ if (!cxxbridge1$string$from_utf8 (self, s, len)) {
8587 panic<std::invalid_argument>(" data for rust::String is not utf-8" );
8688 }
8789}
8890
91+ static void initString (String *self, const char16_t *s, std::size_t len) {
92+ if (!cxxbridge1$string$from_utf16 (self, s, len)) {
93+ panic<std::invalid_argument>(" data for rust::String is not utf-16" );
94+ }
95+ }
96+
8997String::String (const std::string &s) { initString (this , s.data (), s.length ()); }
9098
9199String::String (const char *s) {
@@ -100,6 +108,19 @@ String::String(const char *s, std::size_t len) {
100108 len);
101109}
102110
111+ String::String (const char16_t *s) {
112+ assert (s != nullptr );
113+ initString (this , s, std::char_traits<char16_t >::length (s));
114+ }
115+
116+ String::String (const char16_t *s, std::size_t len) {
117+ assert (s != nullptr || len == 0 );
118+ initString (this ,
119+ s == nullptr && len == 0 ? reinterpret_cast <const char16_t *>(2 )
120+ : s,
121+ len);
122+ }
123+
103124String &String::operator =(const String &other) &noexcept {
104125 if (this != &other) {
105126 cxxbridge1$string$drop (this );
0 commit comments