Merge pull request #90196 from bruvzg/ts_tcase
[TextServer] Expose ICU title case string conversion to scripting.
This commit is contained in:
commit
ca2d28602b
@ -1736,6 +1736,16 @@
|
||||
[b]Note:[/b] The result may be longer or shorter than the original.
|
||||
</description>
|
||||
</method>
|
||||
<method name="string_to_title" qualifiers="const">
|
||||
<return type="String" />
|
||||
<param index="0" name="string" type="String" />
|
||||
<param index="1" name="language" type="String" default="""" />
|
||||
<description>
|
||||
Returns the string converted to title case.
|
||||
[b]Note:[/b] Casing is locale dependent and context sensitive if server support [constant FEATURE_CONTEXT_SENSITIVE_CASE_CONVERSION] feature (supported by [TextServerAdvanced]).
|
||||
[b]Note:[/b] The result may be longer or shorter than the original.
|
||||
</description>
|
||||
</method>
|
||||
<method name="string_to_upper" qualifiers="const">
|
||||
<return type="String" />
|
||||
<param index="0" name="string" type="String" />
|
||||
|
@ -1913,6 +1913,15 @@
|
||||
Returns the string converted to lowercase.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_string_to_title" qualifiers="virtual const">
|
||||
<return type="String" />
|
||||
<param index="0" name="string" type="String" />
|
||||
<param index="1" name="language" type="String" />
|
||||
<description>
|
||||
[b]Optional.[/b]
|
||||
Returns the string converted to title case.
|
||||
</description>
|
||||
</method>
|
||||
<method name="_string_to_upper" qualifiers="virtual const">
|
||||
<return type="String" />
|
||||
<param index="0" name="string" type="String" />
|
||||
|
@ -6976,6 +6976,34 @@ String TextServerAdvanced::_string_to_lower(const String &p_string, const String
|
||||
return String::utf16(lower.ptr(), len);
|
||||
}
|
||||
|
||||
String TextServerAdvanced::_string_to_title(const String &p_string, const String &p_language) const {
|
||||
#ifndef ICU_STATIC_DATA
|
||||
if (!icu_data_loaded) {
|
||||
return p_string.capitalize();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (p_string.is_empty()) {
|
||||
return p_string;
|
||||
}
|
||||
const String lang = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language;
|
||||
|
||||
// Convert to UTF-16.
|
||||
Char16String utf16 = p_string.utf16();
|
||||
|
||||
Vector<char16_t> upper;
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
int32_t len = u_strToTitle(nullptr, 0, utf16.get_data(), -1, nullptr, lang.ascii().get_data(), &err);
|
||||
ERR_FAIL_COND_V_MSG(err != U_BUFFER_OVERFLOW_ERROR, p_string, u_errorName(err));
|
||||
upper.resize(len);
|
||||
err = U_ZERO_ERROR;
|
||||
u_strToTitle(upper.ptrw(), len, utf16.get_data(), -1, nullptr, lang.ascii().get_data(), &err);
|
||||
ERR_FAIL_COND_V_MSG(U_FAILURE(err), p_string, u_errorName(err));
|
||||
|
||||
// Convert back to UTF-32.
|
||||
return String::utf16(upper.ptr(), len);
|
||||
}
|
||||
|
||||
PackedInt32Array TextServerAdvanced::_string_get_word_breaks(const String &p_string, const String &p_language, int64_t p_chars_per_line) const {
|
||||
const String lang = (p_language.is_empty()) ? TranslationServer::get_singleton()->get_tool_locale() : p_language;
|
||||
// Convert to UTF-16.
|
||||
|
@ -991,6 +991,7 @@ public:
|
||||
|
||||
MODBIND2RC(String, string_to_upper, const String &, const String &);
|
||||
MODBIND2RC(String, string_to_lower, const String &, const String &);
|
||||
MODBIND2RC(String, string_to_title, const String &, const String &);
|
||||
|
||||
MODBIND0(cleanup);
|
||||
|
||||
|
@ -4439,6 +4439,10 @@ String TextServerFallback::_string_to_lower(const String &p_string, const String
|
||||
return p_string.to_lower();
|
||||
}
|
||||
|
||||
String TextServerFallback::_string_to_title(const String &p_string, const String &p_language) const {
|
||||
return p_string.capitalize();
|
||||
}
|
||||
|
||||
PackedInt32Array TextServerFallback::_string_get_word_breaks(const String &p_string, const String &p_language, int64_t p_chars_per_line) const {
|
||||
PackedInt32Array ret;
|
||||
|
||||
|
@ -848,6 +848,7 @@ public:
|
||||
|
||||
MODBIND2RC(String, string_to_upper, const String &, const String &);
|
||||
MODBIND2RC(String, string_to_lower, const String &, const String &);
|
||||
MODBIND2RC(String, string_to_title, const String &, const String &);
|
||||
|
||||
MODBIND0(cleanup);
|
||||
|
||||
|
@ -341,6 +341,7 @@ void TextServerExtension::_bind_methods() {
|
||||
|
||||
GDVIRTUAL_BIND(_string_to_upper, "string", "language");
|
||||
GDVIRTUAL_BIND(_string_to_lower, "string", "language");
|
||||
GDVIRTUAL_BIND(_string_to_title, "string", "language");
|
||||
|
||||
GDVIRTUAL_BIND(_parse_structured_text, "parser_type", "args", "text");
|
||||
|
||||
@ -1507,6 +1508,14 @@ String TextServerExtension::string_to_upper(const String &p_string, const String
|
||||
return p_string;
|
||||
}
|
||||
|
||||
String TextServerExtension::string_to_title(const String &p_string, const String &p_language) const {
|
||||
String ret;
|
||||
if (GDVIRTUAL_CALL(_string_to_title, p_string, p_language, ret)) {
|
||||
return ret;
|
||||
}
|
||||
return p_string;
|
||||
}
|
||||
|
||||
String TextServerExtension::string_to_lower(const String &p_string, const String &p_language) const {
|
||||
String ret;
|
||||
if (GDVIRTUAL_CALL(_string_to_lower, p_string, p_language, ret)) {
|
||||
|
@ -566,8 +566,10 @@ public:
|
||||
|
||||
virtual String string_to_upper(const String &p_string, const String &p_language = "") const override;
|
||||
virtual String string_to_lower(const String &p_string, const String &p_language = "") const override;
|
||||
virtual String string_to_title(const String &p_string, const String &p_language = "") const override;
|
||||
GDVIRTUAL2RC(String, _string_to_upper, const String &, const String &);
|
||||
GDVIRTUAL2RC(String, _string_to_lower, const String &, const String &);
|
||||
GDVIRTUAL2RC(String, _string_to_title, const String &, const String &);
|
||||
|
||||
TypedArray<Vector3i> parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;
|
||||
GDVIRTUAL3RC(TypedArray<Vector3i>, _parse_structured_text, StructuredTextParser, const Array &, const String &);
|
||||
|
@ -491,6 +491,7 @@ void TextServer::_bind_methods() {
|
||||
|
||||
ClassDB::bind_method(D_METHOD("string_to_upper", "string", "language"), &TextServer::string_to_upper, DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("string_to_lower", "string", "language"), &TextServer::string_to_lower, DEFVAL(""));
|
||||
ClassDB::bind_method(D_METHOD("string_to_title", "string", "language"), &TextServer::string_to_title, DEFVAL(""));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("parse_structured_text", "parser_type", "args", "text"), &TextServer::parse_structured_text);
|
||||
|
||||
|
@ -546,6 +546,7 @@ public:
|
||||
// Other string operations.
|
||||
virtual String string_to_upper(const String &p_string, const String &p_language = "") const = 0;
|
||||
virtual String string_to_lower(const String &p_string, const String &p_language = "") const = 0;
|
||||
virtual String string_to_title(const String &p_string, const String &p_language = "") const = 0;
|
||||
|
||||
TypedArray<Vector3i> parse_structured_text(StructuredTextParser p_parser_type, const Array &p_args, const String &p_text) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user