Replies: 1 comment 2 replies
-
Godot always uses UTF-32 for string operation. So the character is always a single UTF-32 codepoint. Godot use UTF-8 only to store file on disk. UTF-16 is not used at all (apart from system API calls). |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The
visible_characters
property is used to specify that a certain number of characters are displayed. For example, inhello
, setting it to 2 would only displayhe
.However, when UNICODE is involved everything becomes extremely complex. The term "character" could refer to a variety of things:
char
in C/C++. This only supports English characters and symbols on the keyboard.char
in C#. This only supports characters in the "Basic Multilingual Plane" which includes various languages, but not certain Chinese characters (e.g. "𠮷") and emojis (e.g. "❤️")Rune
in C#. This supports every UNICODE code point, but not every visible grapheme (e.g. 👨🌾).U+200D
+ 🌾).So
visible_characters
is ambiguous and doesn't specify which of the above it means. This is especially a problem for C# due to UTF-16 encoding.From my tests it seems Godot does not use visible graphemes and instead uses runes. The
❤️
emoji is made up of 2 UNICODE code points / runes (HEAVY BLACK HEART
+VARIATION SELECTOR-16
).Test string:
hi ❤️❤️❤️
h
hi
hi
hi ❤️
hi ❤️
hi ❤️❤️
hi ❤️❤️
hi ❤️❤️❤️
hi ❤️❤️❤️
The
𠮷
is not part of the UTF-16 BMP range, but is a single UNICODE code point / rune.Test string:
hi 𠮷𠮷𠮷
h
hi
hi
hi 𠮷
hi 𠮷𠮷
hi 𠮷𠮷𠮷
This behaviour should be changed or documented, because otherwise code can go out of sync with what's displayed.
For example, if a C# script displays the string
a𠮷𠮷𠮷
by iterating over eachchar
and settingvisible_characters
to the index + 1, it will do something like this:The documentation for this property doesn't mention any of this:
Beta Was this translation helpful? Give feedback.
All reactions