Skip to content

Commit 717513a

Browse files
committed
Add is_valid_letter() to TextServer
1 parent 23191b8 commit 717513a

File tree

11 files changed

+799
-0
lines changed

11 files changed

+799
-0
lines changed

core/string/char_range.inc

Lines changed: 663 additions & 0 deletions
Large diffs are not rendered by default.

core/string/char_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ static _FORCE_INLINE_ bool is_unicode_lower_case(char32_t c) {
7070
BSEARCH_CHAR_RANGE(lowercase_letter);
7171
}
7272

73+
static _FORCE_INLINE_ bool is_unicode_letter(char32_t c) {
74+
BSEARCH_CHAR_RANGE(unicode_letter);
75+
}
76+
7377
#undef BSEARCH_CHAR_RANGE
7478

7579
static _FORCE_INLINE_ bool is_ascii_upper_case(char32_t c) {

doc/classes/TextServer.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,13 @@
10881088
- May contain Unicode characters of class XID_Continue in the other positions.
10891089
</description>
10901090
</method>
1091+
<method name="is_valid_letter" qualifiers="const">
1092+
<return type="bool" />
1093+
<param index="0" name="unicode" type="int" />
1094+
<description>
1095+
Returns [code]true[/code] if the given code point is a valid letter, i.e. it belongs to the Unicode category "L".
1096+
</description>
1097+
</method>
10911098
<method name="load_support_data">
10921099
<return type="bool" />
10931100
<param index="0" name="filename" type="String" />

doc/classes/TextServerExtension.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,12 @@
937937
<description>
938938
</description>
939939
</method>
940+
<method name="_is_valid_letter" qualifiers="virtual const">
941+
<return type="bool" />
942+
<param index="0" name="unicode" type="int" />
943+
<description>
944+
</description>
945+
</method>
940946
<method name="_load_support_data" qualifiers="virtual">
941947
<return type="bool" />
942948
<param index="0" name="filename" type="String" />

modules/text_server_adv/text_server_adv.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7229,6 +7229,16 @@ bool TextServerAdvanced::_is_valid_identifier(const String &p_string) const {
72297229
return true;
72307230
}
72317231

7232+
bool TextServerAdvanced::_is_valid_letter(char32_t p_unicode) const {
7233+
#ifndef ICU_STATIC_DATA
7234+
if (!icu_data_loaded) {
7235+
return TextServer::is_valid_letter(p_unicode);
7236+
}
7237+
#endif
7238+
7239+
return u_isalpha(p_unicode);
7240+
}
7241+
72327242
TextServerAdvanced::TextServerAdvanced() {
72337243
_insert_num_systems_lang();
72347244
_insert_feature_sets();

modules/text_server_adv/text_server_adv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,7 @@ class TextServerAdvanced : public TextServerExtension {
979979

980980
MODBIND1RC(String, strip_diacritics, const String &);
981981
MODBIND1RC(bool, is_valid_identifier, const String &);
982+
MODBIND1RC(bool, is_valid_letter, char32_t);
982983

983984
MODBIND2RC(String, string_to_upper, const String &, const String &);
984985
MODBIND2RC(String, string_to_lower, const String &, const String &);

servers/text/text_server_extension.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ void TextServerExtension::_bind_methods() {
327327

328328
GDVIRTUAL_BIND(_strip_diacritics, "string");
329329
GDVIRTUAL_BIND(_is_valid_identifier, "string");
330+
GDVIRTUAL_BIND(_is_valid_letter, "unicode");
330331

331332
GDVIRTUAL_BIND(_string_get_word_breaks, "string", "language", "chars_per_line");
332333
GDVIRTUAL_BIND(_string_get_character_breaks, "string", "language");
@@ -1460,6 +1461,14 @@ bool TextServerExtension::is_valid_identifier(const String &p_string) const {
14601461
return TextServer::is_valid_identifier(p_string);
14611462
}
14621463

1464+
bool TextServerExtension::is_valid_letter(char32_t p_unicode) const {
1465+
bool ret;
1466+
if (GDVIRTUAL_CALL(_is_valid_letter, p_unicode, ret)) {
1467+
return ret;
1468+
}
1469+
return TextServer::is_valid_letter(p_unicode);
1470+
}
1471+
14631472
String TextServerExtension::strip_diacritics(const String &p_string) const {
14641473
String ret;
14651474
if (GDVIRTUAL_CALL(_strip_diacritics, p_string, ret)) {

servers/text/text_server_extension.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ class TextServerExtension : public TextServer {
554554

555555
virtual bool is_valid_identifier(const String &p_string) const override;
556556
GDVIRTUAL1RC(bool, _is_valid_identifier, const String &);
557+
virtual bool is_valid_letter(char32_t p_unicode) const override;
558+
GDVIRTUAL1RC(bool, _is_valid_letter, char32_t);
557559

558560
virtual String string_to_upper(const String &p_string, const String &p_language = "") const override;
559561
virtual String string_to_lower(const String &p_string, const String &p_language = "") const override;

servers/text_server.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ void TextServer::_bind_methods() {
483483

484484
ClassDB::bind_method(D_METHOD("strip_diacritics", "string"), &TextServer::strip_diacritics);
485485
ClassDB::bind_method(D_METHOD("is_valid_identifier", "string"), &TextServer::is_valid_identifier);
486+
ClassDB::bind_method(D_METHOD("is_valid_letter", "unicode"), &TextServer::is_valid_letter);
486487

487488
ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL(""));
488489
ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL(""));
@@ -2091,6 +2092,10 @@ bool TextServer::is_valid_identifier(const String &p_string) const {
20912092
return true;
20922093
}
20932094

2095+
bool TextServer::is_valid_letter(char32_t p_unicode) const {
2096+
return is_unicode_letter(p_unicode);
2097+
}
2098+
20942099
TextServer::TextServer() {
20952100
_init_diacritics_map();
20962101
}

servers/text_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ class TextServer : public RefCounted {
534534

535535
virtual String strip_diacritics(const String &p_string) const;
536536
virtual bool is_valid_identifier(const String &p_string) const;
537+
virtual bool is_valid_letter(char32_t p_unicode) const;
537538

538539
// Other string operations.
539540
virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0;

0 commit comments

Comments
 (0)