Skip to content

Commit a1a886a

Browse files
committed
Use extend_ instead of parse_ for String methods.
1 parent bf1c258 commit a1a886a

File tree

62 files changed

+245
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+245
-274
lines changed

Diff for: core/config/project_settings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ Error ProjectSettings::_load_settings_binary(const String &p_path) {
771771
cs[slen] = 0;
772772
f->get_buffer((uint8_t *)cs.ptr(), slen);
773773
String key;
774-
key.parse_utf8(cs.ptr(), slen);
774+
key.extend_utf8(cs.ptr(), slen);
775775

776776
uint32_t vlen = f->get_32();
777777
Vector<uint8_t> d;

Diff for: core/extension/gdextension_interface.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -873,75 +873,75 @@ static GDExtensionPtrUtilityFunction gdextension_variant_get_ptr_utility_functio
873873

874874
static void gdextension_string_new_with_latin1_chars(GDExtensionUninitializedStringPtr r_dest, const char *p_contents) {
875875
String *dest = memnew_placement(r_dest, String);
876-
dest->parse_latin1(Span<char>(p_contents, p_contents ? strlen(p_contents) : 0));
876+
dest->extend_latin1(Span<char>(p_contents, p_contents ? strlen(p_contents) : 0));
877877
}
878878

879879
static void gdextension_string_new_with_utf8_chars(GDExtensionUninitializedStringPtr r_dest, const char *p_contents) {
880880
String *dest = memnew_placement(r_dest, String);
881-
dest->parse_utf8(p_contents);
881+
dest->extend_utf8(p_contents);
882882
}
883883

884884
static void gdextension_string_new_with_utf16_chars(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents) {
885885
String *dest = memnew_placement(r_dest, String);
886-
dest->parse_utf16(p_contents);
886+
dest->extend_utf16(p_contents);
887887
}
888888

889889
static void gdextension_string_new_with_utf32_chars(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents) {
890890
String *dest = memnew_placement(r_dest, String);
891-
dest->parse_utf32(Span(p_contents, p_contents ? strlen(p_contents) : 0));
891+
dest->extend_utf32(Span(p_contents, p_contents ? strlen(p_contents) : 0));
892892
}
893893

894894
static void gdextension_string_new_with_wide_chars(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents) {
895895
if constexpr (sizeof(wchar_t) == 2) {
896896
// wchar_t is 16 bit (UTF-16).
897897
String *dest = memnew_placement(r_dest, String);
898-
dest->parse_utf16((const char16_t *)p_contents);
898+
dest->extend_utf16((const char16_t *)p_contents);
899899
} else {
900900
// wchar_t is 32 bit (UTF-32).
901901
String *string = memnew_placement(r_dest, String);
902-
string->parse_utf32(Span((const char32_t *)p_contents, p_contents ? strlen(p_contents) : 0));
902+
string->extend_utf32(Span((const char32_t *)p_contents, p_contents ? strlen(p_contents) : 0));
903903
}
904904
}
905905

906906
static void gdextension_string_new_with_latin1_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) {
907907
String *dest = memnew_placement(r_dest, String);
908-
dest->parse_latin1(Span(p_contents, p_contents ? _strlen_clipped(p_contents, p_size) : 0));
908+
dest->extend_latin1(Span(p_contents, p_contents ? _strlen_clipped(p_contents, p_size) : 0));
909909
}
910910

911911
static void gdextension_string_new_with_utf8_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) {
912912
String *dest = memnew_placement(r_dest, String);
913-
dest->parse_utf8(p_contents, p_size);
913+
dest->extend_utf8(p_contents, p_size);
914914
}
915915

916916
static GDExtensionInt gdextension_string_new_with_utf8_chars_and_len2(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size) {
917917
String *dest = memnew_placement(r_dest, String);
918-
return (GDExtensionInt)dest->parse_utf8(p_contents, p_size);
918+
return (GDExtensionInt)dest->extend_utf8(p_contents, p_size);
919919
}
920920

921921
static void gdextension_string_new_with_utf16_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count) {
922922
String *dest = memnew_placement(r_dest, String);
923-
dest->parse_utf16(p_contents, p_char_count);
923+
dest->extend_utf16(p_contents, p_char_count);
924924
}
925925

926926
static GDExtensionInt gdextension_string_new_with_utf16_chars_and_len2(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count, GDExtensionBool p_default_little_endian) {
927927
String *dest = memnew_placement(r_dest, String);
928-
return (GDExtensionInt)dest->parse_utf16(p_contents, p_char_count, p_default_little_endian);
928+
return (GDExtensionInt)dest->extend_utf16(p_contents, p_char_count, p_default_little_endian);
929929
}
930930

931931
static void gdextension_string_new_with_utf32_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_char_count) {
932932
String *string = memnew_placement(r_dest, String);
933-
string->parse_utf32(Span(p_contents, p_contents ? _strlen_clipped(p_contents, p_char_count) : 0));
933+
string->extend_utf32(Span(p_contents, p_contents ? _strlen_clipped(p_contents, p_char_count) : 0));
934934
}
935935

936936
static void gdextension_string_new_with_wide_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_char_count) {
937937
if constexpr (sizeof(wchar_t) == 2) {
938938
// wchar_t is 16 bit (UTF-16).
939939
String *dest = memnew_placement(r_dest, String);
940-
dest->parse_utf16((const char16_t *)p_contents, p_char_count);
940+
dest->extend_utf16((const char16_t *)p_contents, p_char_count);
941941
} else {
942942
// wchar_t is 32 bit (UTF-32).
943943
String *string = memnew_placement(r_dest, String);
944-
string->parse_utf32(Span((const char32_t *)p_contents, p_contents ? _strlen_clipped((const char32_t *)p_contents, p_char_count) : 0));
944+
string->extend_utf32(Span((const char32_t *)p_contents, p_contents ? _strlen_clipped((const char32_t *)p_contents, p_char_count) : 0));
945945
}
946946
}
947947

@@ -1053,14 +1053,14 @@ static void gdextension_string_name_new_with_latin1_chars(GDExtensionUninitializ
10531053

10541054
static void gdextension_string_name_new_with_utf8_chars(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents) {
10551055
String tmp;
1056-
tmp.parse_utf8(p_contents);
1056+
tmp.extend_utf8(p_contents);
10571057

10581058
memnew_placement(r_dest, StringName(tmp));
10591059
}
10601060

10611061
static void gdextension_string_name_new_with_utf8_chars_and_len(GDExtensionUninitializedStringNamePtr r_dest, const char *p_contents, GDExtensionInt p_size) {
10621062
String tmp;
1063-
tmp.parse_utf8(p_contents, p_size);
1063+
tmp.extend_utf8(p_contents, p_size);
10641064

10651065
memnew_placement(r_dest, StringName(tmp));
10661066
}

Diff for: core/io/file_access.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ String FileAccess::get_as_utf8_string(bool p_skip_cr) const {
565565
w[len] = 0;
566566

567567
String s;
568-
s.parse_utf8((const char *)w, len, p_skip_cr);
568+
s.extend_utf8((const char *)w, len, p_skip_cr);
569569
return s;
570570
}
571571

@@ -745,7 +745,7 @@ String FileAccess::get_pascal_string() {
745745
cs[sl] = 0;
746746

747747
String ret;
748-
ret.parse_utf8(cs.ptr(), sl);
748+
ret.extend_utf8(cs.ptr(), sl);
749749
return ret;
750750
}
751751

@@ -838,7 +838,7 @@ String FileAccess::get_file_as_string(const String &p_path, Error *r_error) {
838838
}
839839

840840
String ret;
841-
ret.parse_utf8((const char *)array.ptr(), array.size());
841+
ret.extend_utf8((const char *)array.ptr(), array.size());
842842
return ret;
843843
}
844844

Diff for: core/io/file_access_pack.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
307307
cs[sl] = 0;
308308

309309
String path;
310-
path.parse_utf8(cs.ptr(), sl);
310+
path.extend_utf8(cs.ptr(), sl);
311311

312312
uint64_t ofs = f->get_64();
313313
uint64_t size = f->get_64();

Diff for: core/io/http_client_tcp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ Error HTTPClientTCP::poll() {
484484
// End of response, parse.
485485
response_str.push_back(0);
486486
String response;
487-
response.parse_utf8((const char *)response_str.ptr(), response_str.size());
487+
response.extend_utf8((const char *)response_str.ptr(), response_str.size());
488488
Vector<String> responses = response.split("\n");
489489
body_size = -1;
490490
chunked = false;

Diff for: core/io/marshalls.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r
107107
ERR_FAIL_COND_V(strlen < 0 || strlen + pad > len, ERR_FILE_EOF);
108108

109109
String str;
110-
ERR_FAIL_COND_V(str.parse_utf8((const char *)buf, strlen) != OK, ERR_INVALID_DATA);
110+
ERR_FAIL_COND_V(str.extend_utf8((const char *)buf, strlen) != OK, ERR_INVALID_DATA);
111111
r_string = str;
112112

113113
// Add padding.

Diff for: core/io/plist.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ bool PList::load_file(const String &p_filename) {
648648
ERR_FAIL_COND_V(err != OK, false);
649649

650650
String ret;
651-
ret.parse_utf8((const char *)array.ptr(), array.size());
651+
ret.extend_utf8((const char *)array.ptr(), array.size());
652652
String err_str;
653653
bool ok = load_string(ret, err_str);
654654
ERR_FAIL_COND_V_MSG(!ok, false, "PList: " + err_str);

Diff for: core/io/resource_format_binary.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ StringName ResourceLoaderBinary::_get_string() {
163163
}
164164
f->get_buffer((uint8_t *)&str_buf[0], len);
165165
String s;
166-
s.parse_utf8(&str_buf[0], len);
166+
s.extend_utf8(&str_buf[0], len);
167167
return s;
168168
}
169169

@@ -919,7 +919,7 @@ static String get_ustring(Ref<FileAccess> f) {
919919
str_buf.resize(len);
920920
f->get_buffer((uint8_t *)&str_buf[0], len);
921921
String s;
922-
s.parse_utf8(&str_buf[0], len);
922+
s.extend_utf8(&str_buf[0], len);
923923
return s;
924924
}
925925

@@ -933,7 +933,7 @@ String ResourceLoaderBinary::get_unicode_string() {
933933
}
934934
f->get_buffer((uint8_t *)&str_buf[0], len);
935935
String s;
936-
s.parse_utf8(&str_buf[0], len);
936+
s.extend_utf8(&str_buf[0], len);
937937
return s;
938938
}
939939

Diff for: core/io/stream_peer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ String StreamPeer::get_utf8_string(int p_bytes) {
384384
ERR_FAIL_COND_V(err != OK, String());
385385

386386
String ret;
387-
ret.parse_utf8((const char *)buf.ptr(), buf.size());
387+
ret.extend_utf8((const char *)buf.ptr(), buf.size());
388388
return ret;
389389
}
390390

Diff for: core/io/translation_loader_po.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,17 @@ Ref<Resource> TranslationLoaderPO::load_translation(Ref<FileAccess> f, Error *r_
7676
bool is_plural = false;
7777
for (uint32_t j = 0; j < str_len + 1; j++) {
7878
if (data[j] == 0x04) {
79-
msg_context.parse_utf8((const char *)data.ptr(), j);
79+
msg_context.clear();
80+
msg_context.extend_utf8((const char *)data.ptr(), j);
8081
str_start = j + 1;
8182
}
8283
if (data[j] == 0x00) {
8384
if (is_plural) {
84-
msg_id_plural.parse_utf8((const char *)(data.ptr() + str_start), j - str_start);
85+
msg_id_plural.clear();
86+
msg_id_plural.extend_utf8((const char *)(data.ptr() + str_start), j - str_start);
8587
} else {
86-
msg_id.parse_utf8((const char *)(data.ptr() + str_start), j - str_start);
88+
msg_id.clear();
89+
msg_id.extend_utf8((const char *)(data.ptr() + str_start), j - str_start);
8790
is_plural = true;
8891
}
8992
str_start = j + 1;

Diff for: core/io/xml_parser.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void XMLParser::_ignore_definition() {
9595
while (*P && *P != '>') {
9696
next_char();
9797
}
98-
node_name.parse_utf8(F, P - F);
98+
node_name.clear();
99+
node_name.extend_utf8(F, P - F);
99100

100101
if (*P) {
101102
next_char();

Diff for: core/io/zip_io.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void *zipio_open(voidpf opaque, const char *p_fname, int mode) {
7777
ERR_FAIL_NULL_V(fa, nullptr);
7878

7979
String fname;
80-
fname.parse_utf8(p_fname);
80+
fname.extend_utf8(p_fname);
8181

8282
int file_access_mode = 0;
8383
if (mode & ZLIB_FILEFUNC_MODE_READ) {

Diff for: core/string/optimized_translation.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ StringName OptimizedTranslation::get_message(const StringName &p_src_text, const
254254

255255
if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {
256256
String rstr;
257-
rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
257+
rstr.extend_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
258258

259259
return rstr;
260260
} else {
261261
CharString uncomp;
262262
uncomp.resize(bucket.elem[idx].uncomp_size + 1);
263263
smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
264264
String rstr;
265-
rstr.parse_utf8(uncomp.get_data());
265+
rstr.extend_utf8(uncomp.get_data());
266266
return rstr;
267267
}
268268
}
@@ -284,14 +284,14 @@ Vector<String> OptimizedTranslation::get_translated_message_list() const {
284284
for (int j = 0; j < bucket.size; j++) {
285285
if (bucket.elem[j].comp_size == bucket.elem[j].uncomp_size) {
286286
String rstr;
287-
rstr.parse_utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size);
287+
rstr.extend_utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size);
288288
msgs.push_back(rstr);
289289
} else {
290290
CharString uncomp;
291291
uncomp.resize(bucket.elem[j].uncomp_size + 1);
292292
smaz_decompress(&sptr[bucket.elem[j].str_offset], bucket.elem[j].comp_size, uncomp.ptrw(), bucket.elem[j].uncomp_size);
293293
String rstr;
294-
rstr.parse_utf8(uncomp.get_data());
294+
rstr.extend_utf8(uncomp.get_data());
295295
msgs.push_back(rstr);
296296
}
297297
}

0 commit comments

Comments
 (0)