Use append_ instead of parse_ for String methods.

This commit is contained in:
Lukas Tenbrink
2025-03-24 12:25:48 +01:00
parent 594d64ec24
commit ffa6ef220b
62 changed files with 245 additions and 274 deletions

View File

@ -1593,7 +1593,7 @@ String EditorExportPlatformAndroid::_parse_string(const uint8_t *p_bytes, bool p
}
str8.write[len] = 0;
String str;
str.parse_utf8((const char *)str8.ptr(), len);
str.append_utf8((const char *)str8.ptr(), len);
return str;
} else {
String str;

View File

@ -203,7 +203,7 @@ String FileAccessFilesystemJAndroid::get_line() const {
if (elem == '\n' || elem == '\0') {
// Found the end of the line
const_cast<FileAccessFilesystemJAndroid *>(this)->seek(start_position + line_buffer_position + 1);
if (result.parse_utf8((const char *)line_buffer.ptr(), line_buffer_position, true)) {
if (result.append_utf8((const char *)line_buffer.ptr(), line_buffer_position, true)) {
return String();
}
return result;
@ -211,7 +211,7 @@ String FileAccessFilesystemJAndroid::get_line() const {
}
}
if (result.parse_utf8((const char *)line_buffer.ptr(), line_buffer_position, true)) {
if (result.append_utf8((const char *)line_buffer.ptr(), line_buffer_position, true)) {
return String();
}
return result;

View File

@ -90,7 +90,7 @@ static inline String jstring_to_string(jstring source, JNIEnv *env = nullptr) {
}
const char *const source_utf8 = env->GetStringUTFChars(source, nullptr);
if (source_utf8) {
result.parse_utf8(source_utf8);
result.append_utf8(source_utf8);
env->ReleaseStringUTFChars(source, source_utf8);
}
}

View File

@ -452,7 +452,7 @@ void EditorExportPlatformIOS::_fix_config_file(const Ref<EditorExportPreset> &p_
String str;
String strnew;
str.parse_utf8((const char *)pfile.ptr(), pfile.size());
str.append_utf8((const char *)pfile.ptr(), pfile.size());
Vector<String> lines = str.split("\n");
for (int i = 0; i < lines.size(); i++) {
if (lines[i].contains("$binary")) {

View File

@ -123,7 +123,7 @@
- (void)enterText:(NSString *)substring {
String characters;
characters.parse_utf8([substring UTF8String]);
characters.append_utf8([substring UTF8String]);
for (int i = 0; i < characters.size(); i++) {
int character = characters[i];

View File

@ -359,7 +359,7 @@ String OS_IOS::get_user_data_dir(const String &p_user_dir) const {
if (ret.is_empty()) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (paths && [paths count] >= 1) {
ret.parse_utf8([[paths firstObject] UTF8String]);
ret.append_utf8([[paths firstObject] UTF8String]);
}
}
return ret;
@ -370,7 +370,7 @@ String OS_IOS::get_cache_path() const {
if (ret.is_empty()) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
if (paths && [paths count] >= 1) {
ret.parse_utf8([[paths firstObject] UTF8String]);
ret.append_utf8([[paths firstObject] UTF8String]);
}
}
return ret;

View File

@ -1110,8 +1110,10 @@ void WaylandThread::_wl_output_on_geometry(void *data, struct wl_output *wl_outp
ss->pending_data.physical_size.width = physical_width;
ss->pending_data.physical_size.height = physical_height;
ss->pending_data.make.parse_utf8(make);
ss->pending_data.model.parse_utf8(model);
ss->pending_data.make.clear();
ss->pending_data.make.append_utf8(make);
ss->pending_data.model.clear();
ss->pending_data.model.append_utf8(model);
// `wl_output::done` is a version 2 addition. We'll directly update the data
// for compatibility.
@ -4139,7 +4141,7 @@ String WaylandThread::keyboard_get_layout_name(int p_index) const {
if (ss && ss->xkb_keymap) {
String ret;
ret.parse_utf8(xkb_keymap_layout_get_name(ss->xkb_keymap, p_index));
ret.append_utf8(xkb_keymap_layout_get_name(ss->xkb_keymap, p_index));
return ret;
}

View File

@ -112,7 +112,7 @@ static String get_atom_name(Display *p_disp, Atom p_atom) {
char *name = XGetAtomName(p_disp, p_atom);
ERR_FAIL_NULL_V_MSG(name, String(), "Atom is invalid.");
String ret;
ret.parse_utf8(name);
ret.append_utf8(name);
XFree(name);
return ret;
}
@ -766,7 +766,7 @@ String DisplayServerX11::_clipboard_get_impl(Atom p_source, Window x11_window, A
}
if (success && (data_size > 0)) {
ret.parse_utf8((const char *)incr_data.ptr(), data_size);
ret.append_utf8((const char *)incr_data.ptr(), data_size);
}
} else if (bytes_left > 0) {
// Data is ready and can be processed all at once.
@ -776,7 +776,7 @@ String DisplayServerX11::_clipboard_get_impl(Atom p_source, Window x11_window, A
&len, &dummy, &data);
if (result == Success) {
ret.parse_utf8((const char *)data);
ret.append_utf8((const char *)data);
} else {
print_verbose("Failed to get selection data.");
}
@ -3685,7 +3685,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
}
String tmp;
tmp.parse_utf8(utf8string, utf8bytes);
tmp.append_utf8(utf8string, utf8bytes);
for (int i = 0; i < tmp.length(); i++) {
Ref<InputEventKey> k;
k.instantiate();
@ -3766,7 +3766,7 @@ void DisplayServerX11::_handle_key_event(WindowID p_window, XKeyEvent *p_event,
int str_xkb_size = xkb_compose_state_get_utf8(wd.xkb_state, str_xkb, 255);
String tmp;
tmp.parse_utf8(str_xkb, str_xkb_size);
tmp.append_utf8(str_xkb, str_xkb_size);
for (int i = 0; i < tmp.length(); i++) {
Ref<InputEventKey> k;
k.instantiate();
@ -4121,7 +4121,7 @@ void DisplayServerX11::_xim_preedit_draw_callback(::XIM xim, ::XPointer client_d
if (xim_text->encoding_is_wchar) {
changed_text = String(xim_text->string.wide_char);
} else {
changed_text.parse_utf8(xim_text->string.multi_byte);
changed_text.append_utf8(xim_text->string.multi_byte);
}
if (call_data->chg_length < 0) {

View File

@ -43,7 +43,7 @@ String DirAccessMacOS::fix_unicode_name(const char *p_name) const {
String fname;
if (p_name != nullptr) {
NSString *nsstr = [[NSString stringWithUTF8String:p_name] precomposedStringWithCanonicalMapping];
fname.parse_utf8([nsstr UTF8String]);
fname.append_utf8([nsstr UTF8String]);
}
return fname;
@ -66,7 +66,7 @@ String DirAccessMacOS::get_drive(int p_drive) {
String volname;
NSString *path = [vols[p_drive] path];
volname.parse_utf8([path UTF8String]);
volname.append_utf8([path UTF8String]);
return volname;
}

View File

@ -513,10 +513,10 @@ void DisplayServerMacOS::_update_keyboard_layouts() const {
for (NSUInteger i = 0; i < [list_ime count]; i++) {
LayoutInfo ly;
NSString *name = (__bridge NSString *)TISGetInputSourceProperty((__bridge TISInputSourceRef)[list_ime objectAtIndex:i], kTISPropertyLocalizedName);
ly.name.parse_utf8([name UTF8String]);
ly.name.append_utf8([name UTF8String]);
NSArray *langs = (__bridge NSArray *)TISGetInputSourceProperty((__bridge TISInputSourceRef)[list_ime objectAtIndex:i], kTISPropertyInputSourceLanguages);
ly.code.parse_utf8([(NSString *)[langs objectAtIndex:0] UTF8String]);
ly.code.append_utf8([(NSString *)[langs objectAtIndex:0] UTF8String]);
kbd_layouts.push_back(ly);
if ([name isEqualToString:cur_name]) {
@ -530,10 +530,10 @@ void DisplayServerMacOS::_update_keyboard_layouts() const {
for (NSUInteger i = 0; i < [list_kbd count]; i++) {
LayoutInfo ly;
NSString *name = (__bridge NSString *)TISGetInputSourceProperty((__bridge TISInputSourceRef)[list_kbd objectAtIndex:i], kTISPropertyLocalizedName);
ly.name.parse_utf8([name UTF8String]);
ly.name.append_utf8([name UTF8String]);
NSArray *langs = (__bridge NSArray *)TISGetInputSourceProperty((__bridge TISInputSourceRef)[list_kbd objectAtIndex:i], kTISPropertyInputSourceLanguages);
ly.code.parse_utf8([(NSString *)[langs objectAtIndex:0] UTF8String]);
ly.code.append_utf8([(NSString *)[langs objectAtIndex:0] UTF8String]);
kbd_layouts.push_back(ly);
if ([name isEqualToString:cur_name]) {
@ -1054,7 +1054,7 @@ Error DisplayServerMacOS::_file_dialog_with_options_show(const String &p_title,
// Callback.
Vector<String> files;
String url;
url.parse_utf8([[[panel URL] path] UTF8String]);
url.append_utf8([[[panel URL] path] UTF8String]);
files.push_back(url);
if (callback.is_valid()) {
if (p_options_in_cb) {
@ -1173,7 +1173,7 @@ Error DisplayServerMacOS::_file_dialog_with_options_show(const String &p_title,
Vector<String> files;
for (NSUInteger i = 0; i != [urls count]; ++i) {
String url;
url.parse_utf8([[[urls objectAtIndex:i] path] UTF8String]);
url.append_utf8([[[urls objectAtIndex:i] path] UTF8String]);
files.push_back(url);
}
if (callback.is_valid()) {
@ -1271,7 +1271,7 @@ Error DisplayServerMacOS::dialog_input_text(String p_title, String p_description
[window runModal];
String ret;
ret.parse_utf8([[input stringValue] UTF8String]);
ret.append_utf8([[input stringValue] UTF8String]);
if (p_callback.is_valid()) {
Variant v_result = ret;
@ -1555,7 +1555,7 @@ String DisplayServerMacOS::clipboard_get() const {
NSString *string = [objectsToPaste objectAtIndex:0];
String ret;
ret.parse_utf8([string UTF8String]);
ret.append_utf8([string UTF8String]);
return ret;
}

View File

@ -738,7 +738,7 @@ void EditorExportPlatformMacOS::_make_icon(const Ref<EditorExportPreset> &p_pres
void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist) {
String str;
String strnew;
str.parse_utf8((const char *)plist.ptr(), plist.size());
str.append_utf8((const char *)plist.ptr(), plist.size());
Vector<String> lines = str.split("\n");
for (int i = 0; i < lines.size(); i++) {
if (lines[i].find("$priv_collection") != -1) {
@ -817,7 +817,7 @@ void EditorExportPlatformMacOS::_fix_privacy_manifest(const Ref<EditorExportPres
void EditorExportPlatformMacOS::_fix_plist(const Ref<EditorExportPreset> &p_preset, Vector<uint8_t> &plist, const String &p_binary) {
String str;
String strnew;
str.parse_utf8((const char *)plist.ptr(), plist.size());
str.append_utf8((const char *)plist.ptr(), plist.size());
Vector<String> lines = str.split("\n");
for (int i = 0; i < lines.size(); i++) {
if (lines[i].contains("$binary")) {

View File

@ -271,7 +271,7 @@
[characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])];
String u32text;
u32text.parse_utf16(text.ptr(), text.length());
u32text.append_utf16(text.ptr(), text.length());
for (int i = 0; i < u32text.length(); i++) {
const char32_t codepoint = u32text[i];
@ -653,7 +653,7 @@
[characters getCharacters:(unichar *)text.ptrw() range:NSMakeRange(0, [characters length])];
String u32text;
u32text.parse_utf16(text.ptr(), text.length());
u32text.append_utf16(text.ptr(), text.length());
DisplayServerMacOS::KeyEvent ke;
ke.window_id = window_id;

View File

@ -106,7 +106,7 @@ Vector<String> OS_MacOS::get_granted_permissions() const {
NSURL *url = [NSURL URLByResolvingBookmarkData:bookmark options:NSURLBookmarkResolutionWithSecurityScope relativeToURL:nil bookmarkDataIsStale:&isStale error:&error];
if (!error && !isStale) {
String url_string;
url_string.parse_utf8([[url path] UTF8String]);
url_string.append_utf8([[url path] UTF8String]);
ret.push_back(url_string);
}
}
@ -328,7 +328,7 @@ String OS_MacOS::get_bundle_resource_dir() const {
NSBundle *main = [NSBundle mainBundle];
if (main) {
NSString *resource_path = [main resourcePath];
ret.parse_utf8([resource_path UTF8String]);
ret.append_utf8([resource_path UTF8String]);
}
return ret;
}
@ -340,7 +340,7 @@ String OS_MacOS::get_bundle_icon_path() const {
if (main) {
NSString *icon_path = [[main infoDictionary] objectForKey:@"CFBundleIconFile"];
if (icon_path) {
ret.parse_utf8([icon_path UTF8String]);
ret.append_utf8([icon_path UTF8String]);
}
}
return ret;
@ -383,7 +383,7 @@ String OS_MacOS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
if (found) {
NSArray *paths = NSSearchPathForDirectoriesInDomains(id, NSUserDomainMask, YES);
if (paths && [paths count] >= 1) {
ret.parse_utf8([[paths firstObject] UTF8String]);
ret.append_utf8([[paths firstObject] UTF8String]);
}
}
@ -647,7 +647,7 @@ String OS_MacOS::get_executable_path() const {
return OS::get_executable_path();
} else {
String path;
path.parse_utf8(pathbuf);
path.append_utf8(pathbuf);
return path;
}
@ -720,7 +720,7 @@ Error OS_MacOS::create_instance(const List<String> &p_arguments, ProcessID *r_ch
NSString *nsappname = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
if (nsappname != nil) {
String path;
path.parse_utf8([[[NSBundle mainBundle] bundlePath] UTF8String]);
path.append_utf8([[[NSBundle mainBundle] bundlePath] UTF8String]);
return create_process(path, p_arguments, r_child_id, false);
} else {
return create_process(get_executable_path(), p_arguments, r_child_id, false);
@ -754,7 +754,7 @@ String OS_MacOS::get_unique_id() const {
}
if (serial_number_ns_string) {
serial_number.parse_utf8([serial_number_ns_string UTF8String]);
serial_number.append_utf8([serial_number_ns_string UTF8String]);
}
}

View File

@ -981,7 +981,7 @@ String DisplayServerWindows::clipboard_get() const {
if (mem != nullptr) {
LPTSTR ptr = (LPTSTR)GlobalLock(mem);
if (ptr != nullptr) {
ret.parse_utf8((const char *)ptr);
ret.append_utf8((const char *)ptr);
GlobalUnlock(mem);
}
}
@ -2761,7 +2761,7 @@ String DisplayServerWindows::ime_get_text() const {
int32_t length = ImmGetCompositionStringW(wd.im_himc, GCS_COMPSTR, nullptr, 0);
wchar_t *string = reinterpret_cast<wchar_t *>(memalloc(length));
ImmGetCompositionStringW(wd.im_himc, GCS_COMPSTR, string, length);
ret.parse_utf16((char16_t *)string, length / sizeof(wchar_t));
ret.append_utf16((char16_t *)string, length / sizeof(wchar_t));
memdelete(string);

View File

@ -136,7 +136,7 @@ Error WindowsUtils::copy_and_rename_pdb(const String &p_dll_path) {
}
String utf_path;
Error err = utf_path.parse_utf8(raw_pdb_path);
Error err = utf_path.append_utf8(raw_pdb_path);
ERR_FAIL_COND_V_MSG(err != OK, err, vformat("Failed to read PDB path from '%s'.", p_dll_path));
pdb_info.path = utf_path;
@ -179,7 +179,8 @@ Error WindowsUtils::copy_and_rename_pdb(const String &p_dll_path) {
if (new_expected_buffer_size > original_path_size) {
ERR_FAIL_COND_V_MSG(original_path_size < min_base_size + suffix_size, FAILED, vformat("The original PDB path size in bytes is too small: '%s'. Expected size: %d or more bytes, but available %d.", pdb_info.path, min_base_size + suffix_size, original_path_size));
new_pdb_base_name.parse_utf8(utf8_name, original_path_size - suffix_size);
new_pdb_base_name.clear();
new_pdb_base_name.append_utf8(utf8_name, original_path_size - suffix_size);
new_pdb_base_name[new_pdb_base_name.length() - 1] = '_'; // Restore the last '_'
WARN_PRINT(vformat("The original path size of '%s' in bytes was too small to fit the new name, so it was shortened to '%s%d.pdb'.", pdb_info.path, new_pdb_base_name, max_pdb_names - 1));
}