-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Label.get_total_character_count returns too high value #23720
Comments
Update: looking at the code (
"Regular" characters are counted here. Non-newlines are counted here, and spaces are subtracted from the count here. The reason we get the +2 is that the loop runs up to The reason we get only +1 for an empty string is, I guess, that So I guess this is what should be done:
I'll whip up a PR. There's also a potential issue with other space-like characters, in ASCII but especially in Unicode, but I'll leave that for another day. |
What's the use case for knowing the number of non-space characters though? i.e. when would one use the (fixed) |
It's what This bug is also affecting |
Also document that it only counts visible characters. Fixes #23720
Godot version: 3.0.6
OS/device including version: Arch Linux
Issue description:
The
get_total_character_count()
function onLabel
returns strange values. For the empty string, it return 1. For a string of one non-space character, it returns 3. For increasingly longer strings, it seems increasingly far off the mark.It's not clear from the documentation why there should ever be a difference between
get_total_character_count()
("Returns the total length of the text.") andlen(text)
. So at the very least there's a doc bug here.Steps to reproduce:
Create a scene with a
Label
at the root. Attach the following script:Run the scene and observe the output:
Related issues:
#874 has @reduz saying he fixed it very hard. But that was probably back in the 2.0 days.
The text was updated successfully, but these errors were encountered: