feat: modules moved and engine moved to submodule
This commit is contained in:
parent
dfb5e645cd
commit
c33d2130cc
5136 changed files with 225275 additions and 64485 deletions
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CHAR_RANGE_INC
|
||||
#define CHAR_RANGE_INC
|
||||
#pragma once
|
||||
|
||||
#include "core/typedefs.h"
|
||||
|
||||
|
|
@ -43,7 +42,7 @@ struct CharRange {
|
|||
|
||||
constexpr inline CharRange xid_start[] = {
|
||||
{ 0x41, 0x5a },
|
||||
{ 0x5f, 0x5f }, // Underscore technically isn't in XID_Start, but for our purposes it's included.
|
||||
{ 0x5f, 0x5f },
|
||||
{ 0x61, 0x7a },
|
||||
{ 0xaa, 0xaa },
|
||||
{ 0xb5, 0xb5 },
|
||||
|
|
@ -3629,4 +3628,42 @@ constexpr inline CharRange unicode_letter[] = {
|
|||
{ 0x31350, 0x323af },
|
||||
};
|
||||
|
||||
#endif // CHAR_RANGE_INC
|
||||
// OEM encodings for Alt codes input.
|
||||
|
||||
inline constexpr char32_t alt_code_oem437[256] = {
|
||||
0x0000, 0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022, 0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c,
|
||||
0x25ba, 0x25c4, 0x2195, 0x203c, 0x00b6, 0x00a7, 0x25ac, 0x21a8, 0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x2302,
|
||||
0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0, 0x00e5, 0x00e7, 0x00ea, 0x00eb, 0x00e8, 0x00ef, 0x00ee, 0x00ec, 0x00c4, 0x00c5,
|
||||
0x00c9, 0x00e6, 0x00c6, 0x00f4, 0x00f6, 0x00f2, 0x00fb, 0x00f9, 0x00ff, 0x00d6, 0x00dc, 0x00a2, 0x00a3, 0x00a5, 0x20a7, 0x0192,
|
||||
0x00e1, 0x00ed, 0x00f3, 0x00fa, 0x00f1, 0x00d1, 0x00aa, 0x00ba, 0x00bf, 0x2310, 0x00ac, 0x00bd, 0x00bc, 0x00a1, 0x00ab, 0x00bb,
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
|
||||
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f, 0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b, 0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
|
||||
0x03b1, 0x00df, 0x0393, 0x03c0, 0x03a3, 0x03c3, 0x00b5, 0x03a4, 0x03a6, 0x0398, 0x03a9, 0x03b4, 0x221e, 0x03c6, 0x03b5, 0x2229,
|
||||
0x2261, 0x00b1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00f7, 0x2248, 0x00b0, 0x2219, 0x00b7, 0x221a, 0x207f, 0x00b2, 0x25a0, 0x00a0
|
||||
};
|
||||
|
||||
inline constexpr char32_t alt_code_cp1252[256] = {
|
||||
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x000a, 0x000b, 0x000c, 0x000d, 0x000e, 0x000f,
|
||||
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, 0x0018, 0x0019, 0x001a, 0x001b, 0x001c, 0x001d, 0x001e, 0x001f,
|
||||
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
|
||||
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
|
||||
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048, 0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
|
||||
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058, 0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
|
||||
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068, 0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
|
||||
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e, 0x007f,
|
||||
0x20ac, 0x0081, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030, 0x0160, 0x2039, 0x0152, 0x008d, 0x017d, 0x008f,
|
||||
0x0090, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022, 0x2013, 0x2014, 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x009d, 0x017e, 0x0178,
|
||||
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7, 0x00a8, 0x00a9, 0x00aa, 0x00ab, 0x00ac, 0x00ad, 0x00ae, 0x00af,
|
||||
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00b4, 0x00b5, 0x00b6, 0x00b7, 0x00b8, 0x00b9, 0x00ba, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
|
||||
0x00c0, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8, 0x00c9, 0x00ca, 0x00cb, 0x00cc, 0x00cd, 0x00ce, 0x00cf,
|
||||
0x00d0, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6, 0x00d7, 0x00d8, 0x00d9, 0x00da, 0x00db, 0x00dc, 0x00dd, 0x00de, 0x00df,
|
||||
0x00e0, 0x00e1, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7, 0x00e8, 0x00e9, 0x00ea, 0x00eb, 0x00ec, 0x00ed, 0x00ee, 0x00ef,
|
||||
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8, 0x00f9, 0x00fa, 0x00fb, 0x00fc, 0x00fd, 0x00fe, 0x00ff
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,30 +28,34 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CHAR_UTILS_H
|
||||
#define CHAR_UTILS_H
|
||||
#pragma once
|
||||
|
||||
#include "core/typedefs.h"
|
||||
|
||||
#include "char_range.inc"
|
||||
|
||||
#define BSEARCH_CHAR_RANGE(m_array) \
|
||||
int low = 0; \
|
||||
int high = sizeof(m_array) / sizeof(m_array[0]) - 1; \
|
||||
int middle = (low + high) / 2; \
|
||||
\
|
||||
while (low <= high) { \
|
||||
if (p_char < m_array[middle].start) { \
|
||||
high = middle - 1; \
|
||||
} else if (p_char > m_array[middle].end) { \
|
||||
low = middle + 1; \
|
||||
} else { \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
middle = (low + high) / 2; \
|
||||
} \
|
||||
\
|
||||
#include <iterator>
|
||||
|
||||
static constexpr char hex_char_table_upper[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
static constexpr char hex_char_table_lower[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||
|
||||
#define BSEARCH_CHAR_RANGE(m_array) \
|
||||
int low = 0; \
|
||||
int high = std::size(m_array) - 1; \
|
||||
int middle = (low + high) / 2; \
|
||||
\
|
||||
while (low <= high) { \
|
||||
if (p_char < m_array[middle].start) { \
|
||||
high = middle - 1; \
|
||||
} else if (p_char > m_array[middle].end) { \
|
||||
low = middle + 1; \
|
||||
} else { \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
middle = (low + high) / 2; \
|
||||
} \
|
||||
\
|
||||
return false
|
||||
|
||||
constexpr bool is_unicode_identifier_start(char32_t p_char) {
|
||||
|
|
@ -132,4 +136,6 @@ constexpr bool is_underscore(char32_t p_char) {
|
|||
return (p_char == '_');
|
||||
}
|
||||
|
||||
#endif // CHAR_UTILS_H
|
||||
constexpr bool is_hyphen(char32_t p_char) {
|
||||
return (p_char == '-') || (p_char == 0x2010) || (p_char == 0x2011);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef FUZZY_SEARCH_H
|
||||
#define FUZZY_SEARCH_H
|
||||
#pragma once
|
||||
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
|
|
@ -97,5 +96,3 @@ public:
|
|||
bool search(const String &p_target, FuzzySearchResult &p_result) const;
|
||||
void search_all(const PackedStringArray &p_targets, Vector<FuzzySearchResult> &p_results) const;
|
||||
};
|
||||
|
||||
#endif // FUZZY_SEARCH_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef LOCALES_H
|
||||
#define LOCALES_H
|
||||
#pragma once
|
||||
|
||||
// Windows has some weird locale identifiers which do not honor the ISO 639-1
|
||||
// standardized nomenclature. Whenever those don't conflict with existing ISO
|
||||
|
|
@ -1195,5 +1194,3 @@ static const char *script_list[][2] = {
|
|||
{ "Zanabazar Square", "Zanb" },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
#endif // LOCALES_H
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ void NodePath::simplify() {
|
|||
data->path.remove_at(i - 1);
|
||||
data->path.remove_at(i - 1);
|
||||
i -= 2;
|
||||
if (data->path.size() == 0) {
|
||||
if (data->path.is_empty()) {
|
||||
data->path.push_back(".");
|
||||
break;
|
||||
}
|
||||
|
|
@ -366,7 +366,7 @@ NodePath NodePath::simplified() const {
|
|||
}
|
||||
|
||||
NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
|
||||
if (p_path.size() == 0 && !p_absolute) {
|
||||
if (p_path.is_empty() && !p_absolute) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -378,7 +378,7 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
|
|||
}
|
||||
|
||||
NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) {
|
||||
if (p_path.size() == 0 && p_subpath.size() == 0 && !p_absolute) {
|
||||
if (p_path.is_empty() && p_subpath.is_empty() && !p_absolute) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NODE_PATH_H
|
||||
#define NODE_PATH_H
|
||||
#pragma once
|
||||
|
||||
#include "core/string/string_name.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
|
@ -97,4 +96,6 @@ public:
|
|||
~NodePath();
|
||||
};
|
||||
|
||||
#endif // NODE_PATH_H
|
||||
// Zero-constructing NodePath initializes data to nullptr (and thus empty).
|
||||
template <>
|
||||
struct is_zero_constructible<NodePath> : std::true_type {};
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ void OptimizedTranslation::generate(const Ref<Translation> &p_from) {
|
|||
const Vector<Pair<int, CharString>> &b = buckets[i];
|
||||
HashMap<uint32_t, int> &t = table.write[i];
|
||||
|
||||
if (b.size() == 0) {
|
||||
if (b.is_empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +148,7 @@ void OptimizedTranslation::generate(const Ref<Translation> &p_from) {
|
|||
|
||||
for (int i = 0; i < size; i++) {
|
||||
const HashMap<uint32_t, int> &t = table[i];
|
||||
if (t.size() == 0) {
|
||||
if (t.is_empty()) {
|
||||
htw[i] = 0xFFFFFFFF; //nothing
|
||||
continue;
|
||||
}
|
||||
|
|
@ -253,17 +253,12 @@ StringName OptimizedTranslation::get_message(const StringName &p_src_text, const
|
|||
}
|
||||
|
||||
if (bucket.elem[idx].comp_size == bucket.elem[idx].uncomp_size) {
|
||||
String rstr;
|
||||
rstr.parse_utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
|
||||
|
||||
return rstr;
|
||||
return String::utf8(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].uncomp_size);
|
||||
} else {
|
||||
CharString uncomp;
|
||||
uncomp.resize(bucket.elem[idx].uncomp_size + 1);
|
||||
smaz_decompress(&sptr[bucket.elem[idx].str_offset], bucket.elem[idx].comp_size, uncomp.ptrw(), bucket.elem[idx].uncomp_size);
|
||||
String rstr;
|
||||
rstr.parse_utf8(uncomp.get_data());
|
||||
return rstr;
|
||||
return String::utf8(uncomp.get_data());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -283,15 +278,13 @@ Vector<String> OptimizedTranslation::get_translated_message_list() const {
|
|||
const Bucket &bucket = *(const Bucket *)&btptr[p];
|
||||
for (int j = 0; j < bucket.size; j++) {
|
||||
if (bucket.elem[j].comp_size == bucket.elem[j].uncomp_size) {
|
||||
String rstr;
|
||||
rstr.parse_utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size);
|
||||
String rstr = String::utf8(&sptr[bucket.elem[j].str_offset], bucket.elem[j].uncomp_size);
|
||||
msgs.push_back(rstr);
|
||||
} else {
|
||||
CharString uncomp;
|
||||
uncomp.resize(bucket.elem[j].uncomp_size + 1);
|
||||
smaz_decompress(&sptr[bucket.elem[j].str_offset], bucket.elem[j].comp_size, uncomp.ptrw(), bucket.elem[j].uncomp_size);
|
||||
String rstr;
|
||||
rstr.parse_utf8(uncomp.get_data());
|
||||
String rstr = String::utf8(uncomp.get_data());
|
||||
msgs.push_back(rstr);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef OPTIMIZED_TRANSLATION_H
|
||||
#define OPTIMIZED_TRANSLATION_H
|
||||
#pragma once
|
||||
|
||||
#include "core/string/translation.h"
|
||||
|
||||
|
|
@ -65,7 +64,7 @@ class OptimizedTranslation : public Translation {
|
|||
d = 0x1000193;
|
||||
}
|
||||
while (*p_str) {
|
||||
d = (d * 0x1000193) ^ uint32_t(*p_str);
|
||||
d = (d * 0x1000193) ^ static_cast<uint8_t>(*p_str);
|
||||
p_str++;
|
||||
}
|
||||
|
||||
|
|
@ -86,5 +85,3 @@ public:
|
|||
|
||||
OptimizedTranslation() {}
|
||||
};
|
||||
|
||||
#endif // OPTIMIZED_TRANSLATION_H
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ void __print_line_rich(const String &p_string) {
|
|||
int brk_end = p_string.find_char(']', brk_pos + 1);
|
||||
|
||||
if (brk_end == -1) {
|
||||
txt += p_string.substr(brk_pos, p_string.length() - brk_pos);
|
||||
txt += p_string.substr(brk_pos);
|
||||
output += txt;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef PRINT_STRING_H
|
||||
#define PRINT_STRING_H
|
||||
#pragma once
|
||||
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
|
|
@ -86,5 +85,3 @@ template <typename... Args>
|
|||
void print_line_rich(const Variant &p_var, Args... p_args) {
|
||||
__print_line_rich(stringify_variants(p_var, p_args...));
|
||||
}
|
||||
|
||||
#endif // PRINT_STRING_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef STRING_BUFFER_H
|
||||
#define STRING_BUFFER_H
|
||||
#pragma once
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
|
|
@ -158,5 +157,3 @@ int64_t StringBuffer<SHORT_BUFFER_SIZE>::as_int() {
|
|||
current_buffer_ptr()[string_length] = '\0';
|
||||
return String::to_int(current_buffer_ptr());
|
||||
}
|
||||
|
||||
#endif // STRING_BUFFER_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef STRING_BUILDER_H
|
||||
#define STRING_BUILDER_H
|
||||
#pragma once
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
|
|
@ -80,5 +79,3 @@ public:
|
|||
|
||||
StringBuilder() {}
|
||||
};
|
||||
|
||||
#endif // STRING_BUILDER_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef STRING_NAME_H
|
||||
#define STRING_NAME_H
|
||||
#pragma once
|
||||
|
||||
#include "core/os/mutex.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
|
@ -167,24 +166,49 @@ public:
|
|||
static StringName search(const String &p_name);
|
||||
|
||||
struct AlphCompare {
|
||||
_FORCE_INLINE_ bool operator()(const StringName &l, const StringName &r) const {
|
||||
template <typename LT, typename RT>
|
||||
_FORCE_INLINE_ bool operator()(const LT &l, const RT &r) const {
|
||||
return compare(l, r);
|
||||
}
|
||||
_FORCE_INLINE_ static bool compare(const StringName &l, const StringName &r) {
|
||||
const char *l_cname = l._data ? l._data->cname : "";
|
||||
const char *r_cname = r._data ? r._data->cname : "";
|
||||
|
||||
if (l_cname) {
|
||||
if (r_cname) {
|
||||
return is_str_less(l_cname, r_cname);
|
||||
return str_compare(l_cname, r_cname) < 0;
|
||||
} else {
|
||||
return is_str_less(l_cname, r._data->name.ptr());
|
||||
return str_compare(l_cname, r._data->name.ptr()) < 0;
|
||||
}
|
||||
} else {
|
||||
if (r_cname) {
|
||||
return is_str_less(l._data->name.ptr(), r_cname);
|
||||
return str_compare(l._data->name.ptr(), r_cname) < 0;
|
||||
} else {
|
||||
return is_str_less(l._data->name.ptr(), r._data->name.ptr());
|
||||
return str_compare(l._data->name.ptr(), r._data->name.ptr()) < 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
_FORCE_INLINE_ static bool compare(const String &l, const StringName &r) {
|
||||
const char *r_cname = r._data ? r._data->cname : "";
|
||||
|
||||
if (r_cname) {
|
||||
return str_compare(l.get_data(), r_cname) < 0;
|
||||
} else {
|
||||
return str_compare(l.get_data(), r._data->name.ptr()) < 0;
|
||||
}
|
||||
}
|
||||
_FORCE_INLINE_ static bool compare(const StringName &l, const String &r) {
|
||||
const char *l_cname = l._data ? l._data->cname : "";
|
||||
|
||||
if (l_cname) {
|
||||
return str_compare(l_cname, r.get_data()) < 0;
|
||||
} else {
|
||||
return str_compare(l._data->name.ptr(), r.get_data()) < 0;
|
||||
}
|
||||
}
|
||||
_FORCE_INLINE_ static bool compare(const String &l, const String &r) {
|
||||
return str_compare(l.get_data(), r.get_data()) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
StringName &operator=(const StringName &p_name);
|
||||
|
|
@ -209,7 +233,13 @@ public:
|
|||
StringName() {}
|
||||
|
||||
static void assign_static_unique_class_name(StringName *ptr, const char *p_name);
|
||||
_FORCE_INLINE_ ~StringName() {
|
||||
|
||||
#ifdef SIZE_EXTRA
|
||||
_NO_INLINE_
|
||||
#else
|
||||
_FORCE_INLINE_
|
||||
#endif
|
||||
~StringName() {
|
||||
if (likely(configured) && _data) { //only free if configured
|
||||
unref();
|
||||
}
|
||||
|
|
@ -220,6 +250,10 @@ public:
|
|||
#endif
|
||||
};
|
||||
|
||||
// Zero-constructing StringName initializes _data to nullptr (and thus empty).
|
||||
template <>
|
||||
struct is_zero_constructible<StringName> : std::true_type {};
|
||||
|
||||
bool operator==(const String &p_name, const StringName &p_string_name);
|
||||
bool operator!=(const String &p_name, const StringName &p_string_name);
|
||||
bool operator==(const char *p_name, const StringName &p_string_name);
|
||||
|
|
@ -240,5 +274,3 @@ StringName _scs_create(const char *p_chr, bool p_static = false);
|
|||
*/
|
||||
|
||||
#define SNAME(m_arg) ([]() -> const StringName & { static StringName sname = _scs_create(m_arg, true); return sname; })()
|
||||
|
||||
#endif // STRING_NAME_H
|
||||
|
|
|
|||
|
|
@ -67,10 +67,8 @@ Vector<String> Translation::get_translated_message_list() const {
|
|||
}
|
||||
|
||||
void Translation::_set_messages(const Dictionary &p_messages) {
|
||||
List<Variant> keys;
|
||||
p_messages.get_key_list(&keys);
|
||||
for (const Variant &E : keys) {
|
||||
translation_map[E] = p_messages[E];
|
||||
for (const KeyValue<Variant, Variant> &kv : p_messages) {
|
||||
translation_map[kv.key] = kv.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TRANSLATION_H
|
||||
#define TRANSLATION_H
|
||||
#pragma once
|
||||
|
||||
#include "core/io/resource.h"
|
||||
#include "core/object/gdvirtual.gen.inc"
|
||||
|
|
@ -69,5 +68,3 @@ public:
|
|||
|
||||
Translation() {}
|
||||
};
|
||||
|
||||
#endif // TRANSLATION_H
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ const char32_t *TranslationDomain::_get_accented_version(char32_t p_character) c
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(_character_to_accented) / sizeof(_character_to_accented[0]); i++) {
|
||||
for (unsigned int i = 0; i < std::size(_character_to_accented); i++) {
|
||||
if (_character_to_accented[i].character == p_character) {
|
||||
return _character_to_accented[i].accented_character;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TRANSLATION_DOMAIN_H
|
||||
#define TRANSLATION_DOMAIN_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/ref_counted.h"
|
||||
|
||||
|
|
@ -103,5 +102,3 @@ public:
|
|||
|
||||
TranslationDomain();
|
||||
};
|
||||
|
||||
#endif // TRANSLATION_DOMAIN_H
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@
|
|||
|
||||
#include "translation_po.h"
|
||||
|
||||
#ifdef DEBUG_TRANSLATION_PO
|
||||
#include "core/io/file_access.h"
|
||||
|
||||
#ifdef DEBUG_TRANSLATION_PO
|
||||
void TranslationPO::print_translation_map() {
|
||||
Error err;
|
||||
Ref<FileAccess> file = FileAccess::open("translation_map_print_test.txt", FileAccess::WRITE, &err);
|
||||
|
|
@ -53,8 +53,7 @@ void TranslationPO::print_translation_map() {
|
|||
|
||||
List<StringName> id_l;
|
||||
inner_map.get_key_list(&id_l);
|
||||
for (List<StringName>::Element *E2 = id_l.front(); E2; E2 = E2->next()) {
|
||||
StringName id = E2->get();
|
||||
for (const StringName &id : id_l) {
|
||||
file->store_line("msgid: " + String::utf8(String(id).utf8()));
|
||||
for (int i = 0; i < inner_map[id].size(); i++) {
|
||||
file->store_line("msgstr[" + String::num_int64(i) + "]: " + String::utf8(String(inner_map[id][i]).utf8()));
|
||||
|
|
@ -86,20 +85,16 @@ Dictionary TranslationPO::_get_messages() const {
|
|||
void TranslationPO::_set_messages(const Dictionary &p_messages) {
|
||||
// Construct translation_map from a Dictionary.
|
||||
|
||||
List<Variant> context_l;
|
||||
p_messages.get_key_list(&context_l);
|
||||
for (const Variant &ctx : context_l) {
|
||||
const Dictionary &id_str_map = p_messages[ctx];
|
||||
for (const KeyValue<Variant, Variant> &kv : p_messages) {
|
||||
const Dictionary &id_str_map = kv.value;
|
||||
|
||||
HashMap<StringName, Vector<StringName>> temp_map;
|
||||
List<Variant> id_l;
|
||||
id_str_map.get_key_list(&id_l);
|
||||
for (List<Variant>::Element *E2 = id_l.front(); E2; E2 = E2->next()) {
|
||||
StringName id = E2->get();
|
||||
temp_map[id] = id_str_map[id];
|
||||
for (const KeyValue<Variant, Variant> &kv_id : id_str_map) {
|
||||
StringName id = kv_id.key;
|
||||
temp_map[id] = kv_id.value;
|
||||
}
|
||||
|
||||
translation_map[ctx] = temp_map;
|
||||
translation_map[kv.key] = temp_map;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TRANSLATION_PO_H
|
||||
#define TRANSLATION_PO_H
|
||||
#pragma once
|
||||
|
||||
//#define DEBUG_TRANSLATION_PO
|
||||
|
||||
|
|
@ -99,5 +98,3 @@ public:
|
|||
|
||||
TranslationPO() {}
|
||||
};
|
||||
|
||||
#endif // TRANSLATION_PO_H
|
||||
|
|
|
|||
|
|
@ -135,10 +135,10 @@ TranslationServer::Locale::operator String() const {
|
|||
|
||||
TranslationServer::Locale::Locale(const TranslationServer &p_server, const String &p_locale, bool p_add_defaults) {
|
||||
// Replaces '-' with '_' for macOS style locales.
|
||||
String univ_locale = p_locale.replace("-", "_");
|
||||
String univ_locale = p_locale.replace_char('-', '_');
|
||||
|
||||
// Extract locale elements.
|
||||
Vector<String> locale_elements = univ_locale.get_slice("@", 0).split("_");
|
||||
Vector<String> locale_elements = univ_locale.get_slicec('@', 0).split("_");
|
||||
language = locale_elements[0];
|
||||
if (locale_elements.size() >= 2) {
|
||||
if (locale_elements[1].length() == 4 && is_ascii_upper_case(locale_elements[1][0]) && is_ascii_lower_case(locale_elements[1][1]) && is_ascii_lower_case(locale_elements[1][2]) && is_ascii_lower_case(locale_elements[1][3])) {
|
||||
|
|
@ -162,7 +162,7 @@ TranslationServer::Locale::Locale(const TranslationServer &p_server, const Strin
|
|||
}
|
||||
|
||||
// Try extract script and variant from the extra part.
|
||||
Vector<String> script_extra = univ_locale.get_slice("@", 1).split(";");
|
||||
Vector<String> script_extra = univ_locale.get_slicec('@', 1).split(";");
|
||||
for (int i = 0; i < script_extra.size(); i++) {
|
||||
if (script_extra[i].to_lower() == "cyrillic") {
|
||||
script = "Cyrl";
|
||||
|
|
@ -504,10 +504,10 @@ String TranslationServer::get_tool_locale() {
|
|||
#ifdef TOOLS_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint() || Engine::get_singleton()->is_project_manager_hint()) {
|
||||
const PackedStringArray &locales = editor_domain->get_loaded_locales();
|
||||
if (locales.is_empty()) {
|
||||
return "en";
|
||||
if (locales.has(locale)) {
|
||||
return locale;
|
||||
}
|
||||
return locales[0];
|
||||
return "en";
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TRANSLATION_SERVER_H
|
||||
#define TRANSLATION_SERVER_H
|
||||
#pragma once
|
||||
|
||||
#include "core/string/translation.h"
|
||||
#include "core/string/translation_domain.h"
|
||||
|
|
@ -160,5 +159,3 @@ public:
|
|||
|
||||
TranslationServer();
|
||||
};
|
||||
|
||||
#endif // TRANSLATION_SERVER_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef UCAPS_H
|
||||
#define UCAPS_H
|
||||
#pragma once
|
||||
|
||||
// This file was generated using the `misc/scripts/ucaps_fetch.py` script.
|
||||
|
||||
|
|
@ -3018,5 +3017,3 @@ static int _find_lower(int ch) {
|
|||
|
||||
return ch;
|
||||
}
|
||||
|
||||
#endif // UCAPS_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -28,12 +28,11 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef USTRING_GODOT_H
|
||||
#define USTRING_GODOT_H
|
||||
#pragma once
|
||||
|
||||
// Note: _GODOT suffix added to header guard to avoid conflict with ICU header.
|
||||
|
||||
#include "core/string/char_utils.h"
|
||||
#include "core/string/char_utils.h" // IWYU pragma: export
|
||||
#include "core/templates/cowdata.h"
|
||||
#include "core/templates/vector.h"
|
||||
#include "core/typedefs.h"
|
||||
|
|
@ -98,30 +97,6 @@ constexpr size_t _strlen_clipped(const char32_t *p_str, int p_clip_to_len) {
|
|||
return len;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/* StrRange */
|
||||
/*************************************************************************/
|
||||
|
||||
template <typename Element>
|
||||
struct StrRange {
|
||||
const Element *c_str;
|
||||
size_t len;
|
||||
|
||||
explicit StrRange(const std::nullptr_t p_cstring) :
|
||||
c_str(nullptr), len(0) {}
|
||||
|
||||
explicit StrRange(const Element *p_cstring, const size_t p_len) :
|
||||
c_str(p_cstring), len(p_len) {}
|
||||
|
||||
template <size_t len>
|
||||
explicit StrRange(const Element (&p_cstring)[len]) :
|
||||
c_str(p_cstring), len(strlen(p_cstring)) {}
|
||||
|
||||
static StrRange from_c_str(const Element *p_cstring) {
|
||||
return StrRange(p_cstring, p_cstring ? strlen(p_cstring) : 0);
|
||||
}
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
/* CharProxy */
|
||||
/*************************************************************************/
|
||||
|
|
@ -178,6 +153,10 @@ public:
|
|||
_FORCE_INLINE_ char16_t *ptrw() { return _cowdata.ptrw(); }
|
||||
_FORCE_INLINE_ const char16_t *ptr() const { return _cowdata.ptr(); }
|
||||
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
|
||||
|
||||
_FORCE_INLINE_ operator Span<char16_t>() const { return Span(ptr(), length()); }
|
||||
_FORCE_INLINE_ Span<char16_t> span() const { return Span(ptr(), length()); }
|
||||
|
||||
Error resize(int p_size) { return _cowdata.resize(p_size); }
|
||||
|
||||
_FORCE_INLINE_ char16_t get(int p_index) const { return _cowdata.get(p_index); }
|
||||
|
|
@ -192,10 +171,9 @@ public:
|
|||
_FORCE_INLINE_ CharProxy<char16_t> operator[](int p_index) { return CharProxy<char16_t>(p_index, _cowdata); }
|
||||
|
||||
_FORCE_INLINE_ Char16String() {}
|
||||
_FORCE_INLINE_ Char16String(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ Char16String(Char16String &&p_str) :
|
||||
_cowdata(std::move(p_str._cowdata)) {}
|
||||
_FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ Char16String(const Char16String &p_str) = default;
|
||||
_FORCE_INLINE_ Char16String(Char16String &&p_str) = default;
|
||||
_FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata = p_str._cowdata; }
|
||||
_FORCE_INLINE_ void operator=(Char16String &&p_str) { _cowdata = std::move(p_str._cowdata); }
|
||||
_FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); }
|
||||
|
||||
|
|
@ -204,8 +182,6 @@ public:
|
|||
Char16String &operator+=(char16_t p_char);
|
||||
int length() const { return size() ? size() - 1 : 0; }
|
||||
const char16_t *get_data() const;
|
||||
operator const char16_t *() const { return get_data(); }
|
||||
explicit operator StrRange<char16_t>() const { return StrRange(get_data(), length()); }
|
||||
|
||||
protected:
|
||||
void copy_from(const char16_t *p_cstr);
|
||||
|
|
@ -223,6 +199,10 @@ public:
|
|||
_FORCE_INLINE_ char *ptrw() { return _cowdata.ptrw(); }
|
||||
_FORCE_INLINE_ const char *ptr() const { return _cowdata.ptr(); }
|
||||
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
|
||||
|
||||
_FORCE_INLINE_ operator Span<char>() const { return Span(ptr(), length()); }
|
||||
_FORCE_INLINE_ Span<char> span() const { return Span(ptr(), length()); }
|
||||
|
||||
Error resize(int p_size) { return _cowdata.resize(p_size); }
|
||||
|
||||
_FORCE_INLINE_ char get(int p_index) const { return _cowdata.get(p_index); }
|
||||
|
|
@ -237,10 +217,9 @@ public:
|
|||
_FORCE_INLINE_ CharProxy<char> operator[](int p_index) { return CharProxy<char>(p_index, _cowdata); }
|
||||
|
||||
_FORCE_INLINE_ CharString() {}
|
||||
_FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ CharString(CharString &&p_str) :
|
||||
_cowdata(std::move(p_str._cowdata)) {}
|
||||
_FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ CharString(const CharString &p_str) = default;
|
||||
_FORCE_INLINE_ CharString(CharString &&p_str) = default;
|
||||
_FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata = p_str._cowdata; }
|
||||
_FORCE_INLINE_ void operator=(CharString &&p_str) { _cowdata = std::move(p_str._cowdata); }
|
||||
_FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
|
||||
|
||||
|
|
@ -250,8 +229,6 @@ public:
|
|||
CharString &operator+=(char p_char);
|
||||
int length() const { return size() ? size() - 1 : 0; }
|
||||
const char *get_data() const;
|
||||
operator const char *() const { return get_data(); }
|
||||
explicit operator StrRange<char>() const { return StrRange(get_data(), length()); }
|
||||
|
||||
protected:
|
||||
void copy_from(const char *p_cstr);
|
||||
|
|
@ -267,58 +244,40 @@ class String {
|
|||
static const char32_t _replacement_char;
|
||||
|
||||
// Known-length copy.
|
||||
void parse_latin1(const StrRange<char> &p_cstr);
|
||||
void parse_utf32(const StrRange<char32_t> &p_cstr);
|
||||
void parse_utf32(const char32_t &p_char);
|
||||
void copy_from_unchecked(const char32_t *p_char, int p_length);
|
||||
|
||||
// NULL-terminated c string copy - automatically parse the string to find the length.
|
||||
void parse_latin1(const char *p_cstr) {
|
||||
parse_latin1(StrRange<char>::from_c_str(p_cstr));
|
||||
void append_latin1(const char *p_cstr) {
|
||||
append_latin1(Span(p_cstr, p_cstr ? strlen(p_cstr) : 0));
|
||||
}
|
||||
void parse_latin1(const char *p_cstr, int p_clip_to) {
|
||||
parse_latin1(StrRange(p_cstr, p_cstr ? _strlen_clipped(p_cstr, p_clip_to) : 0));
|
||||
}
|
||||
void parse_utf32(const char32_t *p_cstr) {
|
||||
parse_utf32(StrRange<char32_t>::from_c_str(p_cstr));
|
||||
}
|
||||
void parse_utf32(const char32_t *p_cstr, int p_clip_to) {
|
||||
parse_utf32(StrRange(p_cstr, p_cstr ? _strlen_clipped(p_cstr, p_clip_to) : 0));
|
||||
void append_utf32(const char32_t *p_cstr) {
|
||||
append_utf32(Span(p_cstr, p_cstr ? strlen(p_cstr) : 0));
|
||||
}
|
||||
|
||||
// wchar_t copy_from depends on the platform.
|
||||
void parse_wstring(const StrRange<wchar_t> &p_cstr) {
|
||||
void append_wstring(const Span<wchar_t> &p_cstr) {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
// wchar_t is 16-bit, parse as UTF-16
|
||||
parse_utf16((const char16_t *)p_cstr.c_str, p_cstr.len);
|
||||
append_utf16((const char16_t *)p_cstr.ptr(), p_cstr.size());
|
||||
#else
|
||||
// wchar_t is 32-bit, copy directly
|
||||
parse_utf32((StrRange<char32_t> &)p_cstr);
|
||||
append_utf32((Span<char32_t> &)p_cstr);
|
||||
#endif
|
||||
}
|
||||
void parse_wstring(const wchar_t *p_cstr) {
|
||||
void append_wstring(const wchar_t *p_cstr) {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
// wchar_t is 16-bit, parse as UTF-16
|
||||
parse_utf16((const char16_t *)p_cstr);
|
||||
append_utf16((const char16_t *)p_cstr);
|
||||
#else
|
||||
// wchar_t is 32-bit, copy directly
|
||||
parse_utf32((const char32_t *)p_cstr);
|
||||
#endif
|
||||
}
|
||||
void parse_wstring(const wchar_t *p_cstr, int p_clip_to) {
|
||||
#ifdef WINDOWS_ENABLED
|
||||
// wchar_t is 16-bit, parse as UTF-16
|
||||
parse_utf16((const char16_t *)p_cstr, p_clip_to);
|
||||
#else
|
||||
// wchar_t is 32-bit, copy directly
|
||||
parse_utf32((const char32_t *)p_cstr, p_clip_to);
|
||||
append_utf32((const char32_t *)p_cstr);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool _base_is_subsequence_of(const String &p_string, bool case_insensitive) const;
|
||||
int _count(const String &p_string, int p_from, int p_to, bool p_case_insensitive) const;
|
||||
int _count(const char *p_string, int p_from, int p_to, bool p_case_insensitive) const;
|
||||
String _camelcase_to_underscore() const;
|
||||
String _separate_compound_words() const;
|
||||
|
||||
public:
|
||||
enum {
|
||||
|
|
@ -327,6 +286,10 @@ public:
|
|||
|
||||
_FORCE_INLINE_ char32_t *ptrw() { return _cowdata.ptrw(); }
|
||||
_FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }
|
||||
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
|
||||
|
||||
_FORCE_INLINE_ operator Span<char32_t>() const { return Span(ptr(), length()); }
|
||||
_FORCE_INLINE_ Span<char32_t> span() const { return Span(ptr(), length()); }
|
||||
|
||||
void remove_at(int p_index) { _cowdata.remove_at(p_index); }
|
||||
|
||||
|
|
@ -334,7 +297,6 @@ public:
|
|||
|
||||
_FORCE_INLINE_ char32_t get(int p_index) const { return _cowdata.get(p_index); }
|
||||
_FORCE_INLINE_ void set(int p_index, const char32_t &p_elem) { _cowdata.set(p_index, p_elem); }
|
||||
_FORCE_INLINE_ int size() const { return _cowdata.size(); }
|
||||
Error resize(int p_size) { return _cowdata.resize(p_size); }
|
||||
|
||||
_FORCE_INLINE_ const char32_t &operator[](int p_index) const {
|
||||
|
|
@ -351,6 +313,9 @@ public:
|
|||
bool operator==(const String &p_str) const;
|
||||
bool operator!=(const String &p_str) const;
|
||||
String operator+(const String &p_str) const;
|
||||
String operator+(const char *p_char) const;
|
||||
String operator+(const wchar_t *p_char) const;
|
||||
String operator+(const char32_t *p_char) const;
|
||||
String operator+(char32_t p_char) const;
|
||||
|
||||
String &operator+=(const String &);
|
||||
|
|
@ -362,7 +327,7 @@ public:
|
|||
bool operator==(const char *p_str) const;
|
||||
bool operator==(const wchar_t *p_str) const;
|
||||
bool operator==(const char32_t *p_str) const;
|
||||
bool operator==(const StrRange<char32_t> &p_str_range) const;
|
||||
bool operator==(const Span<char32_t> &p_str_range) const;
|
||||
|
||||
bool operator!=(const char *p_str) const;
|
||||
bool operator!=(const wchar_t *p_str) const;
|
||||
|
|
@ -429,12 +394,18 @@ public:
|
|||
String replace_first(const char *p_key, const char *p_with) const;
|
||||
String replace(const String &p_key, const String &p_with) const;
|
||||
String replace(const char *p_key, const char *p_with) const;
|
||||
String replace_char(char32_t p_key, char32_t p_with) const;
|
||||
String replace_chars(const String &p_keys, char32_t p_with) const;
|
||||
String replace_chars(const char *p_keys, char32_t p_with) const;
|
||||
String replacen(const String &p_key, const String &p_with) const;
|
||||
String replacen(const char *p_key, const char *p_with) const;
|
||||
String repeat(int p_count) const;
|
||||
String reverse() const;
|
||||
String insert(int p_at_pos, const String &p_string) const;
|
||||
String erase(int p_pos, int p_chars = 1) const;
|
||||
String remove_char(char32_t p_what) const;
|
||||
String remove_chars(const String &p_chars) const;
|
||||
String remove_chars(const char *p_chars) const;
|
||||
String pad_decimals(int p_digits) const;
|
||||
String pad_zeros(int p_digits) const;
|
||||
String trim_prefix(const String &p_prefix) const;
|
||||
|
|
@ -452,7 +423,11 @@ public:
|
|||
static String num_real(float p_num, bool p_trailing = true);
|
||||
static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
|
||||
static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
|
||||
static String chr(char32_t p_char);
|
||||
static String chr(char32_t p_char) {
|
||||
String string;
|
||||
string.append_utf32(Span(&p_char, 1));
|
||||
return string;
|
||||
}
|
||||
static String md5(const uint8_t *p_md5);
|
||||
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
|
||||
Vector<uint8_t> hex_decode() const;
|
||||
|
|
@ -477,6 +452,7 @@ public:
|
|||
String to_camel_case() const;
|
||||
String to_pascal_case() const;
|
||||
String to_snake_case() const;
|
||||
String to_kebab_case() const;
|
||||
|
||||
String get_with_code_lines() const;
|
||||
int get_slice_count(const String &p_splitter) const;
|
||||
|
|
@ -489,7 +465,7 @@ public:
|
|||
Vector<String> split(const char *p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
|
||||
Vector<String> rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
|
||||
Vector<String> rsplit(const char *p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
|
||||
Vector<String> split_spaces() const;
|
||||
Vector<String> split_spaces(int p_maxsplit = 0) const;
|
||||
Vector<double> split_floats(const String &p_splitter, bool p_allow_empty = true) const;
|
||||
Vector<float> split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const;
|
||||
Vector<int> split_ints(const String &p_splitter, bool p_allow_empty = true) const;
|
||||
|
|
@ -521,13 +497,44 @@ public:
|
|||
char32_t unicode_at(int p_idx) const;
|
||||
|
||||
CharString ascii(bool p_allow_extended = false) const;
|
||||
CharString utf8() const;
|
||||
Error parse_utf8(const char *p_utf8, int p_len = -1, bool p_skip_cr = false);
|
||||
// Parse an ascii string.
|
||||
// If any character is > 127, an error will be logged, and 0xfffd will be inserted.
|
||||
Error append_ascii(const Span<char> &p_range);
|
||||
static String ascii(const Span<char> &p_range) {
|
||||
String s;
|
||||
s.append_ascii(p_range);
|
||||
return s;
|
||||
}
|
||||
CharString latin1() const { return ascii(true); }
|
||||
void append_latin1(const Span<char> &p_cstr);
|
||||
static String latin1(const Span<char> &p_string) {
|
||||
String string;
|
||||
string.append_latin1(p_string);
|
||||
return string;
|
||||
}
|
||||
|
||||
CharString utf8(Vector<uint8_t> *r_ch_length_map = nullptr) const;
|
||||
Error append_utf8(const char *p_utf8, int p_len = -1, bool p_skip_cr = false);
|
||||
Error append_utf8(const Span<char> &p_range, bool p_skip_cr = false) {
|
||||
return append_utf8(p_range.ptr(), p_range.size(), p_skip_cr);
|
||||
}
|
||||
static String utf8(const char *p_utf8, int p_len = -1);
|
||||
static String utf8(const Span<char> &p_range) { return utf8(p_range.ptr(), p_range.size()); }
|
||||
|
||||
Char16String utf16() const;
|
||||
Error parse_utf16(const char16_t *p_utf16, int p_len = -1, bool p_default_little_endian = true);
|
||||
Error append_utf16(const char16_t *p_utf16, int p_len = -1, bool p_default_little_endian = true);
|
||||
Error append_utf16(const Span<char16_t> p_range, bool p_skip_cr = false) {
|
||||
return append_utf16(p_range.ptr(), p_range.size(), p_skip_cr);
|
||||
}
|
||||
static String utf16(const char16_t *p_utf16, int p_len = -1);
|
||||
static String utf16(const Span<char16_t> &p_range) { return utf16(p_range.ptr(), p_range.size()); }
|
||||
|
||||
void append_utf32(const Span<char32_t> &p_cstr);
|
||||
static String utf32(const Span<char32_t> &p_span) {
|
||||
String string;
|
||||
string.append_utf32(p_span);
|
||||
return string;
|
||||
}
|
||||
|
||||
static uint32_t hash(const char32_t *p_cstr, int p_len); /* hash the string */
|
||||
static uint32_t hash(const char32_t *p_cstr); /* hash the string */
|
||||
|
|
@ -567,6 +574,7 @@ public:
|
|||
String xml_unescape() const;
|
||||
String uri_encode() const;
|
||||
String uri_decode() const;
|
||||
String uri_file_decode() const;
|
||||
String c_escape() const;
|
||||
String c_escape_multiline() const;
|
||||
String c_unescape() const;
|
||||
|
|
@ -599,10 +607,12 @@ public:
|
|||
*/
|
||||
|
||||
_FORCE_INLINE_ String() {}
|
||||
_FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ String(String &&p_str) :
|
||||
_cowdata(std::move(p_str._cowdata)) {}
|
||||
_FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); }
|
||||
_FORCE_INLINE_ String(const String &p_str) = default;
|
||||
_FORCE_INLINE_ String(String &&p_str) = default;
|
||||
#ifdef SIZE_EXTRA
|
||||
_NO_INLINE_ ~String() {}
|
||||
#endif
|
||||
_FORCE_INLINE_ void operator=(const String &p_str) { _cowdata = p_str._cowdata; }
|
||||
_FORCE_INLINE_ void operator=(String &&p_str) { _cowdata = std::move(p_str._cowdata); }
|
||||
|
||||
Vector<uint8_t> to_ascii_buffer() const;
|
||||
|
|
@ -610,41 +620,38 @@ public:
|
|||
Vector<uint8_t> to_utf16_buffer() const;
|
||||
Vector<uint8_t> to_utf32_buffer() const;
|
||||
Vector<uint8_t> to_wchar_buffer() const;
|
||||
Vector<uint8_t> to_multibyte_char_buffer(const String &p_encoding = String()) const;
|
||||
|
||||
// Constructors for NULL terminated C strings.
|
||||
String(const char *p_cstr) {
|
||||
parse_latin1(p_cstr);
|
||||
append_latin1(p_cstr);
|
||||
}
|
||||
String(const wchar_t *p_cstr) {
|
||||
parse_wstring(p_cstr);
|
||||
append_wstring(p_cstr);
|
||||
}
|
||||
String(const char32_t *p_cstr) {
|
||||
parse_utf32(p_cstr);
|
||||
}
|
||||
String(const char *p_cstr, int p_clip_to_len) {
|
||||
parse_latin1(p_cstr, p_clip_to_len);
|
||||
}
|
||||
String(const wchar_t *p_cstr, int p_clip_to_len) {
|
||||
parse_wstring(p_cstr, p_clip_to_len);
|
||||
}
|
||||
String(const char32_t *p_cstr, int p_clip_to_len) {
|
||||
parse_utf32(p_cstr, p_clip_to_len);
|
||||
append_utf32(p_cstr);
|
||||
}
|
||||
|
||||
// Copy assignment for NULL terminated C strings.
|
||||
void operator=(const char *p_cstr) {
|
||||
parse_latin1(p_cstr);
|
||||
clear();
|
||||
append_latin1(p_cstr);
|
||||
}
|
||||
void operator=(const wchar_t *p_cstr) {
|
||||
parse_wstring(p_cstr);
|
||||
clear();
|
||||
append_wstring(p_cstr);
|
||||
}
|
||||
void operator=(const char32_t *p_cstr) {
|
||||
parse_utf32(p_cstr);
|
||||
clear();
|
||||
append_utf32(p_cstr);
|
||||
}
|
||||
|
||||
explicit operator StrRange<char32_t>() const { return StrRange(get_data(), length()); }
|
||||
};
|
||||
|
||||
// Zero-constructing String initializes _cowdata.ptr() to nullptr and thus empty.
|
||||
template <>
|
||||
struct is_zero_constructible<String> : std::true_type {};
|
||||
|
||||
bool operator==(const char *p_chr, const String &p_str);
|
||||
bool operator==(const wchar_t *p_chr, const String &p_str);
|
||||
bool operator!=(const char *p_chr, const String &p_str);
|
||||
|
|
@ -678,21 +685,13 @@ struct FileNoCaseComparator {
|
|||
};
|
||||
|
||||
template <typename L, typename R>
|
||||
_FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
|
||||
_FORCE_INLINE_ int64_t str_compare(const L *l_ptr, const R *r_ptr) {
|
||||
while (true) {
|
||||
const char32_t l = *l_ptr;
|
||||
const char32_t r = *r_ptr;
|
||||
|
||||
if (l == 0 && r == 0) {
|
||||
return false;
|
||||
} else if (l == 0) {
|
||||
return true;
|
||||
} else if (r == 0) {
|
||||
return false;
|
||||
} else if (l < r) {
|
||||
return true;
|
||||
} else if (l > r) {
|
||||
return false;
|
||||
if (l == 0 || l != r) {
|
||||
return static_cast<int64_t>(l) - static_cast<int64_t>(r);
|
||||
}
|
||||
|
||||
l_ptr++;
|
||||
|
|
@ -792,5 +791,3 @@ _FORCE_INLINE_ Vector<String> sarray(P... p_args) {
|
|||
sarray_add_str(arr, p_args...);
|
||||
return arr;
|
||||
}
|
||||
|
||||
#endif // USTRING_GODOT_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue