Skip to content

Commit 626ff95

Browse files
committed
Deduplicate string::parse_utf32(char32_t) in favor of just using the Span based function.
1 parent 701505e commit 626ff95

File tree

2 files changed

+1
-25
lines changed

2 files changed

+1
-25
lines changed

core/string/ustring.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -347,29 +347,6 @@ void String::parse_utf32(const Span<char32_t> &p_cstr) {
347347
*dst = 0;
348348
}
349349

350-
void String::parse_utf32(const char32_t &p_char) {
351-
if (p_char == 0) {
352-
print_unicode_error("NUL character", true);
353-
return;
354-
}
355-
356-
resize(2);
357-
358-
char32_t *dst = ptrw();
359-
360-
if ((p_char & 0xfffff800) == 0xd800) {
361-
print_unicode_error(vformat("Unpaired surrogate (%x)", (uint32_t)p_char));
362-
dst[0] = _replacement_char;
363-
} else if (p_char > 0x10ffff) {
364-
print_unicode_error(vformat("Invalid unicode codepoint (%x)", (uint32_t)p_char));
365-
dst[0] = _replacement_char;
366-
} else {
367-
dst[0] = p_char;
368-
}
369-
370-
dst[1] = 0;
371-
}
372-
373350
// assumes the following have already been validated:
374351
// p_char != nullptr
375352
// p_length > 0

core/string/ustring.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ class String {
436436
static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
437437
static String chr(char32_t p_char) {
438438
String string;
439-
string.parse_utf32(p_char);
439+
string.parse_utf32(Span(&p_char, 1));
440440
return string;
441441
}
442442
static String md5(const uint8_t *p_md5);
@@ -540,7 +540,6 @@ class String {
540540
static String utf16(const Span<char16_t> &p_range) { return utf16(p_range.ptr(), p_range.size()); }
541541

542542
void parse_utf32(const Span<char32_t> &p_cstr);
543-
void parse_utf32(const char32_t &p_char);
544543

545544
static uint32_t hash(const char32_t *p_cstr, int p_len); /* hash the string */
546545
static uint32_t hash(const char32_t *p_cstr); /* hash the string */

0 commit comments

Comments
 (0)