Commit graph

386 commits

Author SHA1 Message Date
Pāvels Nadtočajevs
9ae5f09c20 Fix editor UI showing empty string for unknown locales. 2025-02-13 08:07:26 +02:00
Pāvels Nadtočajevs
e9fd760357 Use fallback locale from project settings instead of hardcoded "en" for TextServer. 2025-02-10 08:55:50 +02:00
bruvzg
a6ff518763 Add ZWSP to the list of space characters. 2025-02-06 10:31:32 +02:00
Pāvels Nadtočajevs
b50d9742c2 Fix is_valid_float, Variant parser, Expression parser, script highlighter, and TextServer not handing capital E in scientific notation. 2025-02-05 18:39:40 +02:00
Jakub Marcowski
104857687c
Update ucaps.h to contain proper case matchings 2025-01-29 12:37:33 +01:00
Lukas Tenbrink
dbf189e28f Lock the StringName::mutex after hashing the string, to spend less time hoarding it unnecessarily. 2025-01-15 21:20:48 +01:00
Lukas Tenbrink
2e600789dd Optimize String ==, ends_with and begins_with by using memcmp. 2025-01-13 15:23:08 +01:00
Rémi Verschelde
ad74e337b9 Merge pull request #100954 from Bromeon/bugfix/nodepath-slice
Fix `NodePath::slice()` incorrect behavior for subname indexing
2025-01-10 23:05:56 +01:00
Lukas Tenbrink
b2d881a73a Optimize _count by replacing a full copy with a CoW copy for the full-string count case. 2025-01-02 18:16:06 +01:00
Jan Haller
df66ea74d7 Fix NodePath::slice() incorrect behavior for subname indexing
Adjust slice boundaries in `NodePath` logic to correctly handle subnames.
Update test cases to reflect these changes.
2024-12-30 21:22:26 +01:00
Thaddeus Crews
416a86f47c
Merge pull request #100434 from Ivorforce/string-copy-from-rename
Rename `String::copy_from` functions to their respective encodings (`parse_latin1`, `parse_wstring`, `parse_utf32`).
2024-12-19 19:59:57 -06:00
Thaddeus Crews
bf9ef5f8a5
Merge pull request #100564 from YYF233333/iwyu
Remove unused headers in core
2024-12-19 19:59:55 -06:00
Thaddeus Crews
a94b559f9b
Merge pull request #100483 from Ivorforce/string-name-move-semantics
Add move semantics (constructor, assignment) to `StringName`.
2024-12-19 19:59:34 -06:00
Yufeng Ying
be86ce3103 Apply iwyu suggestion in core. 2024-12-19 00:43:47 +08:00
HP van Braam
240f510fa7 Core ubsan fixes
This fixes UBSAN errors reported by running our testsuite, importing the
TPS demo, and running the TPS demo. I have tried, wherever possible, to
fix issues related to reported issues but not directly reported by UBSAN
because thse code paths just happened to not have been exercised in
these cases.

These fixes apply only to errors reported, and caused by, core/

The following things have been changed:

* Make sure there are no implicit sign changing casts in core.
* Explicitly type enums that are part of a public API such that users of
  the API cannot pass in wrongly-sized values leading to potential stack
  corruption.
* Ensure that memcpy is never called with invalid or null pointers as
  this is undefined behavior, and when the engine is built with
  optimizations turned on leads to memory corruption and hard to debug
  crashes.
* Replace enum values only used as static values with constexpr static
  const values instead. This has no runtime overhead. This makes it so
  that the size of the enums is explicit.
* Make sure that nan and inf is handled consistently in String.
* Implement a _to_int template to ensure that all of the paths use the
  same algorhithm, and correct the negative integer case.
* Changed the way the json serializer precision work, and added tests to
  verify the new behavior. The behavior doesn't quite match master in
  particulary for negative doubles as the original code tried to cast -inf
  to an int. This then led to negative doubles losing all but one of
  their decimal points when serializing. Behavior in GDScript remains
  unchanged.
2024-12-18 14:31:12 +01:00
Lukas Tenbrink
8c4e674770 Add move semantics (constructor, assignment) to StringName. 2024-12-16 19:02:52 +01:00
Lukas Tenbrink
df3e9291c6 Rename String::copy_from functions to their respective encodings (parse_latin1, parse_wstring, parse_utf32). 2024-12-15 21:46:50 +01:00
Thaddeus Crews
9fba62a938
Merge pull request #100239 from Ivorforce/cowdata-move-constructor
Add move constructor and move assignment to `CowData`, `String`, `Char16String`, `CharString`, and `Vector`.
2024-12-12 16:13:30 -06:00
Rémi Verschelde
7b15c0622e
Merge pull request #100295 from Ivorforce/string-builder-inplace
Optimize `StringBuilder.as_string` by constructing the string in-place and skipping unnecessary checks.
2024-12-12 14:10:21 +01:00
Lukas Tenbrink
76af9537ed Optimize StringBuilder.as_string by constructing the string in-place and skipping unnecessary checks.
Co-authored-by: YYF233333 <nbyyf2002@mail.ustc.edu.cn>
2024-12-12 01:35:02 +01:00
Lukas Tenbrink
ef3eecd34e Optimize String.count and String.countn by avoiding repeated reallocations. 2024-12-12 00:28:13 +01:00
Lukas Tenbrink
57073ba14e Add move constructor and move assignment to CowData, String, Char16String, CharString and Vector. 2024-12-11 15:52:15 +01:00
Thaddeus Crews
ba66c478c0
Merge pull request #100041 from Ivorforce/optimize-string-similarity
Optimize String.similarity by avoiding allocation for bigrams.
2024-12-10 14:16:00 -06:00
Thaddeus Crews
3ef8e835c2
Merge pull request #99775 from Ivorforce/string-builder-template-append
Optimize StringBuilder by using `LocalVector` instead of `Vector`.
2024-12-10 14:15:58 -06:00
Lukas Tenbrink
a3f48f7047 Optimize String construction from statically known strings allowing strlen to be evaluated at compile time, where possible. 2024-12-09 21:47:28 +01:00
Thaddeus Crews
4b1a51d3e3
Merge pull request #100075 from demolke/simplify
Fix handling of leading `..` in simplify_path
2024-12-09 14:33:34 -06:00
Thaddeus Crews
5b312d0e59
Merge pull request #99816 from Ivorforce/string-copy-from-optimizations
Optimize `String::copy_from` and `String::copy_from_unchecked` implementations, improving String allocation speed.
2024-12-09 14:33:33 -06:00
Thaddeus Crews
473c28b1ad
Merge pull request #98118 from bruvzg/escape_colors
Add support for 24-bit color escape sequences, simplify `print_rich` BBCode parsing.
2024-12-09 14:33:25 -06:00
Lukas Tenbrink
8df2dbe2f6 Optimize StringBuilder append for static strings, and as_string(). 2024-12-08 16:39:25 +01:00
Lukas Tenbrink
875b48366c Optimize String.similarity by avoiding allocation for bigrams. 2024-12-08 13:28:40 +01:00
Lukas Tenbrink
e1c42392c2 Improve string copy_from and copy_from_unchecked implementations, by making use of caller contracts and language spec (NULL termination and casts). 2024-12-07 01:41:25 +01:00
Lukas Tenbrink
b5c31ebb41 Add contains_char() for single-character 'contains' calls. 2024-12-06 20:23:35 +01:00
demolke
964e2b3a9e Fix handling of leading .. in simplify_path
Prior to this `..\..\texture.png` was incorrectly simplified to `texture.png`
2024-12-06 07:53:55 +01:00
Thaddeus Crews
45734bd451
Merge pull request #99817 from Ivorforce/strlen-char32_t
Use `strlen()` 3 times instead of custom length check implementations in ustring
2024-12-05 14:12:21 -06:00
Thaddeus Crews
06cce0e81a
Merge pull request #100016 from Ivorforce/camelcase-to-underscore-rolling-cache
Optimize `_camelcase_to_underscore` (and thus `String.capitalize`)
2024-12-05 14:11:59 -06:00
Lukas Tenbrink
8d82933c7c Optimize _camelcase_to_underscore (and thus String.capitalize) by using a rolling cache of character attributes, instead of re-computing each iteration. 2024-12-04 18:39:38 +01:00
Lukas Tenbrink
0d2e13bcb8 Optimize is_valid_filename and validate_filename by caching invalid filename characters, instead of re-splitting each call. 2024-12-04 17:54:11 +01:00
Rémi Verschelde
d7515dddaa
Merge pull request #99815 from Ivorforce/string-name-not-equal-inline
Move StringName `!=` operator to the header file to make it inlineable.
2024-12-02 15:51:43 +01:00
Lukas Tenbrink
2b39314461 Abstract the implementation of 3 ustring string length checks with strlen, adding an implementation for char32_t. 2024-12-02 15:19:20 +01:00
Lukas Tenbrink
a47d29cf11 Move StringName != to the header file to make it inlineable. 2024-12-01 19:50:34 +01:00
Rémi Verschelde
56a7dba10b
Merge pull request #99799 from akien-mga/fix-typos
Fix various typos and code style issues
2024-11-29 22:02:53 +01:00
Rémi Verschelde
88e81ee730
Fix various typos and code style issues 2024-11-28 17:40:42 +01:00
Lukas Tenbrink
884cbb5333 Don't repeat calls to strlen in split, and make splitter_length const in get_slice. 2024-11-28 01:55:48 +01:00
Thaddeus Crews
e7b11d1c99 Merge pull request #99527 from RandomShaper/fix_threaded_trans
Make loading translations from threads safe
2024-11-22 14:54:26 -06:00
Pedro J. Estébanez
7a25173ff4 Make loading translations from threads safe 2024-11-22 09:44:07 +01:00
Dan Nicholson
6f4fadf65d Expose standardize_locale add_default param publicly
Comparing locales can have surprising outcomes since it standardizes
locales with defaults. For example, zh and zh_CN result in an exact
match since the defaults change them both to zh_Hans_CN. Expose the
add_default parameter publicly with a default of false so the fully
standardized locale can be inspected.
2024-11-21 16:50:31 -07:00
A Thousand Ships
68f638cf02
Use (r)find_char instead of (r)find for single characters 2024-11-17 10:02:18 +01:00
Thaddeus Crews
ebf49317a2
Merge pull request #97923 from kisg/translation_server_siof_fix
Make TranslationServer singleton variable inline.
2024-11-12 12:13:01 -06:00
Thaddeus Crews
27b394c52a
Merge pull request #98743 from dbnicholson/improve-compare-locales
Improve locale comparison
2024-11-12 09:27:54 -06:00
Dan Nicholson
2dd409fd70 Improve locale comparison
Since 9456454109, country specific locales are always preferred over
country-less locales even when the OS locale country doesn't match. For
example, running the Godot editor with locale es_ES will result in the
es_AR locale being chosen even though the es locale would be better.

The change happened because the score of the es_AR locale and the es
locale are the same when comparing to es_ES. Change this by parsing
locale strings into a Locale structure and decreasing the score when
script, country or variant are set in both but not matched. For the
es_ES case, this causes the es_AR score to be decreased since the
countries don't match. On the other hand, the es locale is not decreased
since it doesn't specify a country.
2024-11-12 06:06:50 -07:00