mirror of https://github.com/godotengine/godot
Merge 21235ef37e into 15ff450680
This commit is contained in:
commit
5f5477172a
|
|
@ -111,10 +111,6 @@ Char16String &Char16String::operator+=(char16_t p_char) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void Char16String::operator=(const char16_t *p_cstr) {
|
||||
copy_from(p_cstr);
|
||||
}
|
||||
|
||||
const char16_t *Char16String::get_data() const {
|
||||
if (size()) {
|
||||
return &operator[](0);
|
||||
|
|
@ -123,27 +119,19 @@ const char16_t *Char16String::get_data() const {
|
|||
}
|
||||
}
|
||||
|
||||
void Char16String::copy_from(const char16_t *p_cstr) {
|
||||
if (!p_cstr) {
|
||||
Error Char16String::copy_from(const StrRange<char16_t> &p_cstr) {
|
||||
if (p_cstr.len == 0) {
|
||||
resize(0);
|
||||
return;
|
||||
return OK;
|
||||
}
|
||||
|
||||
const char16_t *s = p_cstr;
|
||||
for (; *s; s++) {
|
||||
}
|
||||
size_t len = s - p_cstr;
|
||||
const Error err = resize(p_cstr.len + 1); // Include terminating null char.
|
||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to copy char16_t string.");
|
||||
|
||||
if (len == 0) {
|
||||
resize(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = resize(++len); // include terminating null char
|
||||
|
||||
ERR_FAIL_COND_MSG(err != OK, "Failed to copy char16_t string.");
|
||||
|
||||
memcpy(ptrw(), p_cstr, len * sizeof(char16_t));
|
||||
char16_t *dst = ptrw();
|
||||
memcpy(dst, p_cstr.c_str, p_cstr.len * sizeof(char16_t));
|
||||
dst[p_cstr.len] = _null;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
|
@ -181,10 +169,6 @@ CharString &CharString::operator+=(char p_char) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
void CharString::operator=(const char *p_cstr) {
|
||||
copy_from(p_cstr);
|
||||
}
|
||||
|
||||
const char *CharString::get_data() const {
|
||||
if (size()) {
|
||||
return &operator[](0);
|
||||
|
|
@ -193,24 +177,19 @@ const char *CharString::get_data() const {
|
|||
}
|
||||
}
|
||||
|
||||
void CharString::copy_from(const char *p_cstr) {
|
||||
if (!p_cstr) {
|
||||
Error CharString::copy_from(const StrRange<char> &p_cstr) {
|
||||
if (p_cstr.len == 0) {
|
||||
resize(0);
|
||||
return;
|
||||
return OK;
|
||||
}
|
||||
|
||||
size_t len = strlen(p_cstr);
|
||||
const Error err = resize(p_cstr.len + 1); // Include terminating null char.
|
||||
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to copy C-string.");
|
||||
|
||||
if (len == 0) {
|
||||
resize(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Error err = resize(++len); // include terminating null char
|
||||
|
||||
ERR_FAIL_COND_MSG(err != OK, "Failed to copy C-string.");
|
||||
|
||||
memcpy(ptrw(), p_cstr, len);
|
||||
char *dst = ptrw();
|
||||
memcpy(dst, p_cstr.c_str, p_cstr.len);
|
||||
dst[p_cstr.len] = _null;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
|
|
|||
|
|
@ -197,9 +197,9 @@ public:
|
|||
_cowdata(std::move(p_str._cowdata)) {}
|
||||
_FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ void operator=(Char16String &&p_str) { _cowdata = std::move(p_str._cowdata); }
|
||||
_FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); }
|
||||
_FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(StrRange<char16_t>::from_c_str(p_cstr)); }
|
||||
|
||||
void operator=(const char16_t *p_cstr);
|
||||
void operator=(const char16_t *p_cstr) { copy_from(StrRange<char16_t>::from_c_str(p_cstr)); }
|
||||
bool operator<(const Char16String &p_right) const;
|
||||
Char16String &operator+=(char16_t p_char);
|
||||
int length() const { return size() ? size() - 1 : 0; }
|
||||
|
|
@ -208,7 +208,7 @@ public:
|
|||
explicit operator StrRange<char16_t>() const { return StrRange(get_data(), length()); }
|
||||
|
||||
protected:
|
||||
void copy_from(const char16_t *p_cstr);
|
||||
Error copy_from(const StrRange<char16_t> &p_cstr);
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
|
|
@ -242,9 +242,9 @@ public:
|
|||
_cowdata(std::move(p_str._cowdata)) {}
|
||||
_FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ void operator=(CharString &&p_str) { _cowdata = std::move(p_str._cowdata); }
|
||||
_FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
|
||||
_FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(StrRange<char>::from_c_str(p_cstr)); }
|
||||
|
||||
void operator=(const char *p_cstr);
|
||||
void operator=(const char *p_cstr) { copy_from(StrRange<char>::from_c_str(p_cstr)); }
|
||||
bool operator<(const CharString &p_right) const;
|
||||
bool operator==(const CharString &p_right) const;
|
||||
CharString &operator+=(char p_char);
|
||||
|
|
@ -254,7 +254,7 @@ public:
|
|||
explicit operator StrRange<char>() const { return StrRange(get_data(), length()); }
|
||||
|
||||
protected:
|
||||
void copy_from(const char *p_cstr);
|
||||
Error copy_from(const StrRange<char> &p_cstr);
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
|
|
|
|||
Loading…
Reference in New Issue