More precise documentation for GDExtension String constructors (bytes vs. character count)

This commit is contained in:
Jan Haller 2023-09-24 18:17:05 +02:00
parent 43be9fa0c8
commit c770937db5
2 changed files with 15 additions and 15 deletions

View File

@ -753,25 +753,25 @@ static void gdextension_string_new_with_utf8_chars_and_len(GDExtensionUninitiali
dest->parse_utf8(p_contents, p_size); dest->parse_utf8(p_contents, p_size);
} }
static void gdextension_string_new_with_utf16_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_size) { static void gdextension_string_new_with_utf16_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count) {
memnew_placement(r_dest, String); memnew_placement(r_dest, String);
String *dest = reinterpret_cast<String *>(r_dest); String *dest = reinterpret_cast<String *>(r_dest);
dest->parse_utf16(p_contents, p_size); dest->parse_utf16(p_contents, p_char_count);
} }
static void gdextension_string_new_with_utf32_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_size) { static void gdextension_string_new_with_utf32_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_char_count) {
memnew_placement(r_dest, String((const char32_t *)p_contents, p_size)); memnew_placement(r_dest, String((const char32_t *)p_contents, p_char_count));
} }
static void gdextension_string_new_with_wide_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_size) { static void gdextension_string_new_with_wide_chars_and_len(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_char_count) {
if constexpr (sizeof(wchar_t) == 2) { if constexpr (sizeof(wchar_t) == 2) {
// wchar_t is 16 bit, parse. // wchar_t is 16 bit, parse.
memnew_placement(r_dest, String); memnew_placement(r_dest, String);
String *dest = reinterpret_cast<String *>(r_dest); String *dest = reinterpret_cast<String *>(r_dest);
dest->parse_utf16((const char16_t *)p_contents, p_size); dest->parse_utf16((const char16_t *)p_contents, p_char_count);
} else { } else {
// wchar_t is 32 bit, copy. // wchar_t is 32 bit, copy.
memnew_placement(r_dest, String((const char32_t *)p_contents, p_size)); memnew_placement(r_dest, String((const char32_t *)p_contents, p_char_count));
} }
} }

View File

@ -1432,7 +1432,7 @@ typedef void (*GDExtensionInterfaceStringNewWithWideChars)(GDExtensionUninitiali
* *
* @param r_dest A pointer to a Variant to hold the newly created String. * @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a Latin-1 encoded C string. * @param p_contents A pointer to a Latin-1 encoded C string.
* @param p_size The number of characters. * @param p_size The number of characters (= number of bytes).
*/ */
typedef void (*GDExtensionInterfaceStringNewWithLatin1CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size); typedef void (*GDExtensionInterfaceStringNewWithLatin1CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size);
@ -1444,7 +1444,7 @@ typedef void (*GDExtensionInterfaceStringNewWithLatin1CharsAndLen)(GDExtensionUn
* *
* @param r_dest A pointer to a Variant to hold the newly created String. * @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a UTF-8 encoded C string. * @param p_contents A pointer to a UTF-8 encoded C string.
* @param p_size The number of characters. * @param p_size The number of bytes (not code units).
*/ */
typedef void (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size); typedef void (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size);
@ -1456,9 +1456,9 @@ typedef void (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen)(GDExtensionUnin
* *
* @param r_dest A pointer to a Variant to hold the newly created String. * @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a UTF-16 encoded C string. * @param p_contents A pointer to a UTF-16 encoded C string.
* @param p_size The number of characters. * @param p_size The number of characters (not bytes).
*/ */
typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_size); typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count);
/** /**
* @name string_new_with_utf32_chars_and_len * @name string_new_with_utf32_chars_and_len
@ -1468,9 +1468,9 @@ typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUni
* *
* @param r_dest A pointer to a Variant to hold the newly created String. * @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a UTF-32 encoded C string. * @param p_contents A pointer to a UTF-32 encoded C string.
* @param p_size The number of characters. * @param p_size The number of characters (not bytes).
*/ */
typedef void (*GDExtensionInterfaceStringNewWithUtf32CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_size); typedef void (*GDExtensionInterfaceStringNewWithUtf32CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_char_count);
/** /**
* @name string_new_with_wide_chars_and_len * @name string_new_with_wide_chars_and_len
@ -1480,9 +1480,9 @@ typedef void (*GDExtensionInterfaceStringNewWithUtf32CharsAndLen)(GDExtensionUni
* *
* @param r_dest A pointer to a Variant to hold the newly created String. * @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a wide C string. * @param p_contents A pointer to a wide C string.
* @param p_size The number of characters. * @param p_size The number of characters (not bytes).
*/ */
typedef void (*GDExtensionInterfaceStringNewWithWideCharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_size); typedef void (*GDExtensionInterfaceStringNewWithWideCharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_char_count);
/** /**
* @name string_to_latin1_chars * @name string_to_latin1_chars