Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b46383e

Browse files
committedMar 30, 2025·
Rename _strlen_clipped to strnlen (and use the system equivalent for char * inputs).
1 parent ba34829 commit b46383e

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed
 

‎core/extension/gdextension_interface.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ static void gdextension_string_new_with_wide_chars(GDExtensionUninitializedStrin
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->append_latin1(Span(p_contents, p_contents ? _strlen_clipped(p_contents, p_size) : 0));
908+
dest->append_latin1(Span(p_contents, p_contents ? strnlen(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) {
@@ -930,7 +930,7 @@ static GDExtensionInt gdextension_string_new_with_utf16_chars_and_len2(GDExtensi
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->append_utf32(Span(p_contents, p_contents ? _strlen_clipped(p_contents, p_char_count) : 0));
933+
string->append_utf32(Span(p_contents, p_contents ? strnlen(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) {
@@ -941,7 +941,7 @@ static void gdextension_string_new_with_wide_chars_and_len(GDExtensionUninitiali
941941
} else {
942942
// wchar_t is 32 bit (UTF-32).
943943
String *string = memnew_placement(r_dest, String);
944-
string->append_utf32(Span((const char32_t *)p_contents, p_contents ? _strlen_clipped((const char32_t *)p_contents, p_char_count) : 0));
944+
string->append_utf32(Span((const char32_t *)p_contents, p_contents ? strnlen((const char32_t *)p_contents, p_char_count) : 0));
945945
}
946946
}
947947

‎core/string/ustring.h

+2-13
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,8 @@ constexpr size_t strlen(const wchar_t *str) {
7373
#endif
7474
}
7575

76-
constexpr size_t _strlen_clipped(const char *p_str, int p_clip_to_len) {
77-
if (p_clip_to_len < 0) {
78-
return strlen(p_str);
79-
}
80-
81-
int len = 0;
82-
while (len < p_clip_to_len && *(p_str++) != 0) {
83-
len++;
84-
}
85-
return len;
86-
}
87-
88-
constexpr size_t _strlen_clipped(const char32_t *p_str, int p_clip_to_len) {
76+
// strnlen equivalent function for char32_t * arguments.
77+
constexpr size_t strnlen(const char32_t *p_str, int p_clip_to_len) {
8978
if (p_clip_to_len < 0) {
9079
return strlen(p_str);
9180
}

0 commit comments

Comments
 (0)
Please sign in to comment.