ustring.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /**************************************************************************/
  2. /* ustring.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef USTRING_GODOT_H
  31. #define USTRING_GODOT_H
  32. // Note: _GODOT suffix added to header guard to avoid conflict with ICU header.
  33. #include "core/string/char_utils.h"
  34. #include "core/templates/cowdata.h"
  35. #include "core/templates/vector.h"
  36. #include "core/typedefs.h"
  37. #include "core/variant/array.h"
  38. /*************************************************************************/
  39. /* CharProxy */
  40. /*************************************************************************/
  41. template <class T>
  42. class CharProxy {
  43. friend class Char16String;
  44. friend class CharString;
  45. friend class String;
  46. const int _index;
  47. CowData<T> &_cowdata;
  48. static const T _null = 0;
  49. _FORCE_INLINE_ CharProxy(const int &p_index, CowData<T> &p_cowdata) :
  50. _index(p_index),
  51. _cowdata(p_cowdata) {}
  52. public:
  53. _FORCE_INLINE_ CharProxy(const CharProxy<T> &p_other) :
  54. _index(p_other._index),
  55. _cowdata(p_other._cowdata) {}
  56. _FORCE_INLINE_ operator T() const {
  57. if (unlikely(_index == _cowdata.size())) {
  58. return _null;
  59. }
  60. return _cowdata.get(_index);
  61. }
  62. _FORCE_INLINE_ const T *operator&() const {
  63. return _cowdata.ptr() + _index;
  64. }
  65. _FORCE_INLINE_ void operator=(const T &p_other) const {
  66. _cowdata.set(_index, p_other);
  67. }
  68. _FORCE_INLINE_ void operator=(const CharProxy<T> &p_other) const {
  69. _cowdata.set(_index, p_other.operator T());
  70. }
  71. };
  72. /*************************************************************************/
  73. /* Char16String */
  74. /*************************************************************************/
  75. class Char16String {
  76. CowData<char16_t> _cowdata;
  77. static const char16_t _null;
  78. public:
  79. _FORCE_INLINE_ char16_t *ptrw() { return _cowdata.ptrw(); }
  80. _FORCE_INLINE_ const char16_t *ptr() const { return _cowdata.ptr(); }
  81. _FORCE_INLINE_ int size() const { return _cowdata.size(); }
  82. Error resize(int p_size) { return _cowdata.resize(p_size); }
  83. _FORCE_INLINE_ char16_t get(int p_index) const { return _cowdata.get(p_index); }
  84. _FORCE_INLINE_ void set(int p_index, const char16_t &p_elem) { _cowdata.set(p_index, p_elem); }
  85. _FORCE_INLINE_ const char16_t &operator[](int p_index) const {
  86. if (unlikely(p_index == _cowdata.size())) {
  87. return _null;
  88. }
  89. return _cowdata.get(p_index);
  90. }
  91. _FORCE_INLINE_ CharProxy<char16_t> operator[](int p_index) { return CharProxy<char16_t>(p_index, _cowdata); }
  92. _FORCE_INLINE_ Char16String() {}
  93. _FORCE_INLINE_ Char16String(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
  94. _FORCE_INLINE_ void operator=(const Char16String &p_str) { _cowdata._ref(p_str._cowdata); }
  95. _FORCE_INLINE_ Char16String(const char16_t *p_cstr) { copy_from(p_cstr); }
  96. void operator=(const char16_t *p_cstr);
  97. bool operator<(const Char16String &p_right) const;
  98. Char16String &operator+=(char16_t p_char);
  99. int length() const { return size() ? size() - 1 : 0; }
  100. const char16_t *get_data() const;
  101. operator const char16_t *() const { return get_data(); };
  102. protected:
  103. void copy_from(const char16_t *p_cstr);
  104. };
  105. /*************************************************************************/
  106. /* CharString */
  107. /*************************************************************************/
  108. class CharString {
  109. CowData<char> _cowdata;
  110. static const char _null;
  111. public:
  112. _FORCE_INLINE_ char *ptrw() { return _cowdata.ptrw(); }
  113. _FORCE_INLINE_ const char *ptr() const { return _cowdata.ptr(); }
  114. _FORCE_INLINE_ int size() const { return _cowdata.size(); }
  115. Error resize(int p_size) { return _cowdata.resize(p_size); }
  116. _FORCE_INLINE_ char get(int p_index) const { return _cowdata.get(p_index); }
  117. _FORCE_INLINE_ void set(int p_index, const char &p_elem) { _cowdata.set(p_index, p_elem); }
  118. _FORCE_INLINE_ const char &operator[](int p_index) const {
  119. if (unlikely(p_index == _cowdata.size())) {
  120. return _null;
  121. }
  122. return _cowdata.get(p_index);
  123. }
  124. _FORCE_INLINE_ CharProxy<char> operator[](int p_index) { return CharProxy<char>(p_index, _cowdata); }
  125. _FORCE_INLINE_ CharString() {}
  126. _FORCE_INLINE_ CharString(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
  127. _FORCE_INLINE_ void operator=(const CharString &p_str) { _cowdata._ref(p_str._cowdata); }
  128. _FORCE_INLINE_ CharString(const char *p_cstr) { copy_from(p_cstr); }
  129. void operator=(const char *p_cstr);
  130. bool operator<(const CharString &p_right) const;
  131. bool operator==(const CharString &p_right) const;
  132. CharString &operator+=(char p_char);
  133. int length() const { return size() ? size() - 1 : 0; }
  134. const char *get_data() const;
  135. operator const char *() const { return get_data(); };
  136. protected:
  137. void copy_from(const char *p_cstr);
  138. };
  139. /*************************************************************************/
  140. /* String */
  141. /*************************************************************************/
  142. struct StrRange {
  143. const char32_t *c_str;
  144. int len;
  145. StrRange(const char32_t *p_c_str = nullptr, int p_len = 0) {
  146. c_str = p_c_str;
  147. len = p_len;
  148. }
  149. };
  150. class String {
  151. CowData<char32_t> _cowdata;
  152. static const char32_t _null;
  153. static const char32_t _replacement_char;
  154. void copy_from(const char *p_cstr);
  155. void copy_from(const char *p_cstr, const int p_clip_to);
  156. void copy_from(const wchar_t *p_cstr);
  157. void copy_from(const wchar_t *p_cstr, const int p_clip_to);
  158. void copy_from(const char32_t *p_cstr);
  159. void copy_from(const char32_t *p_cstr, const int p_clip_to);
  160. void copy_from(const char32_t &p_char);
  161. void copy_from_unchecked(const char32_t *p_char, const int p_length);
  162. bool _base_is_subsequence_of(const String &p_string, bool case_insensitive) const;
  163. int _count(const String &p_string, int p_from, int p_to, bool p_case_insensitive) const;
  164. String _camelcase_to_underscore() const;
  165. public:
  166. enum {
  167. npos = -1 ///<for "some" compatibility with std::string (npos is a huge value in std::string)
  168. };
  169. _FORCE_INLINE_ char32_t *ptrw() { return _cowdata.ptrw(); }
  170. _FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }
  171. void remove_at(int p_index) { _cowdata.remove_at(p_index); }
  172. _FORCE_INLINE_ void clear() { resize(0); }
  173. _FORCE_INLINE_ char32_t get(int p_index) const { return _cowdata.get(p_index); }
  174. _FORCE_INLINE_ void set(int p_index, const char32_t &p_elem) { _cowdata.set(p_index, p_elem); }
  175. _FORCE_INLINE_ int size() const { return _cowdata.size(); }
  176. Error resize(int p_size) { return _cowdata.resize(p_size); }
  177. _FORCE_INLINE_ const char32_t &operator[](int p_index) const {
  178. if (unlikely(p_index == _cowdata.size())) {
  179. return _null;
  180. }
  181. return _cowdata.get(p_index);
  182. }
  183. _FORCE_INLINE_ CharProxy<char32_t> operator[](int p_index) { return CharProxy<char32_t>(p_index, _cowdata); }
  184. bool operator==(const String &p_str) const;
  185. bool operator!=(const String &p_str) const;
  186. String operator+(const String &p_str) const;
  187. String operator+(char32_t p_char) const;
  188. String &operator+=(const String &);
  189. String &operator+=(char32_t p_char);
  190. String &operator+=(const char *p_str);
  191. String &operator+=(const wchar_t *p_str);
  192. String &operator+=(const char32_t *p_str);
  193. /* Compatibility Operators */
  194. void operator=(const char *p_str);
  195. void operator=(const wchar_t *p_str);
  196. void operator=(const char32_t *p_str);
  197. bool operator==(const char *p_str) const;
  198. bool operator==(const wchar_t *p_str) const;
  199. bool operator==(const char32_t *p_str) const;
  200. bool operator==(const StrRange &p_str_range) const;
  201. bool operator!=(const char *p_str) const;
  202. bool operator!=(const wchar_t *p_str) const;
  203. bool operator!=(const char32_t *p_str) const;
  204. bool operator<(const char32_t *p_str) const;
  205. bool operator<(const char *p_str) const;
  206. bool operator<(const wchar_t *p_str) const;
  207. bool operator<(const String &p_str) const;
  208. bool operator<=(const String &p_str) const;
  209. bool operator>(const String &p_str) const;
  210. bool operator>=(const String &p_str) const;
  211. signed char casecmp_to(const String &p_str) const;
  212. signed char nocasecmp_to(const String &p_str) const;
  213. signed char naturalcasecmp_to(const String &p_str) const;
  214. signed char naturalnocasecmp_to(const String &p_str) const;
  215. const char32_t *get_data() const;
  216. /* standard size stuff */
  217. _FORCE_INLINE_ int length() const {
  218. int s = size();
  219. return s ? (s - 1) : 0; // length does not include zero
  220. }
  221. bool is_valid_string() const;
  222. /* debug, error messages */
  223. void print_unicode_error(const String &p_message, bool p_critical = false) const;
  224. /* complex helpers */
  225. String substr(int p_from, int p_chars = -1) const;
  226. int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed
  227. int find(const char *p_str, int p_from = 0) const; ///< return <0 if failed
  228. int find_char(const char32_t &p_char, int p_from = 0) const; ///< return <0 if failed
  229. int findn(const String &p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive
  230. int rfind(const String &p_str, int p_from = -1) const; ///< return <0 if failed
  231. int rfindn(const String &p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive
  232. int findmk(const Vector<String> &p_keys, int p_from = 0, int *r_key = nullptr) const; ///< return <0 if failed
  233. bool match(const String &p_wildcard) const;
  234. bool matchn(const String &p_wildcard) const;
  235. bool begins_with(const String &p_string) const;
  236. bool begins_with(const char *p_string) const;
  237. bool ends_with(const String &p_string) const;
  238. bool is_enclosed_in(const String &p_string) const;
  239. bool is_subsequence_of(const String &p_string) const;
  240. bool is_subsequence_ofn(const String &p_string) const;
  241. bool is_quoted() const;
  242. Vector<String> bigrams() const;
  243. float similarity(const String &p_string) const;
  244. String format(const Variant &values, String placeholder = "{_}") const;
  245. String replace_first(const String &p_key, const String &p_with) const;
  246. String replace(const String &p_key, const String &p_with) const;
  247. String replace(const char *p_key, const char *p_with) const;
  248. String replacen(const String &p_key, const String &p_with) const;
  249. String repeat(int p_count) const;
  250. String insert(int p_at_pos, const String &p_string) const;
  251. String erase(int p_pos, int p_chars = 1) const;
  252. String pad_decimals(int p_digits) const;
  253. String pad_zeros(int p_digits) const;
  254. String trim_prefix(const String &p_prefix) const;
  255. String trim_suffix(const String &p_suffix) const;
  256. String lpad(int min_length, const String &character = " ") const;
  257. String rpad(int min_length, const String &character = " ") const;
  258. String sprintf(const Array &values, bool *error) const;
  259. String quote(String quotechar = "\"") const;
  260. String unquote() const;
  261. static String num(double p_num, int p_decimals = -1);
  262. static String num_scientific(double p_num);
  263. static String num_real(double p_num, bool p_trailing = true);
  264. static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
  265. static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
  266. static String chr(char32_t p_char);
  267. static String md5(const uint8_t *p_md5);
  268. static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
  269. Vector<uint8_t> hex_decode() const;
  270. bool is_numeric() const;
  271. double to_float() const;
  272. int64_t hex_to_int() const;
  273. int64_t bin_to_int() const;
  274. int64_t to_int() const;
  275. static int64_t to_int(const char *p_str, int p_len = -1);
  276. static int64_t to_int(const wchar_t *p_str, int p_len = -1);
  277. static int64_t to_int(const char32_t *p_str, int p_len = -1, bool p_clamp = false);
  278. static double to_float(const char *p_str);
  279. static double to_float(const wchar_t *p_str, const wchar_t **r_end = nullptr);
  280. static double to_float(const char32_t *p_str, const char32_t **r_end = nullptr);
  281. static uint32_t num_characters(int64_t p_int);
  282. String capitalize() const;
  283. String to_camel_case() const;
  284. String to_pascal_case() const;
  285. String to_snake_case() const;
  286. String get_with_code_lines() const;
  287. int get_slice_count(String p_splitter) const;
  288. String get_slice(String p_splitter, int p_slice) const;
  289. String get_slicec(char32_t p_splitter, int p_slice) const;
  290. Vector<String> split(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
  291. Vector<String> rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
  292. Vector<String> split_spaces() const;
  293. Vector<double> split_floats(const String &p_splitter, bool p_allow_empty = true) const;
  294. Vector<float> split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const;
  295. Vector<int> split_ints(const String &p_splitter, bool p_allow_empty = true) const;
  296. Vector<int> split_ints_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const;
  297. String join(Vector<String> parts) const;
  298. static char32_t char_uppercase(char32_t p_char);
  299. static char32_t char_lowercase(char32_t p_char);
  300. String to_upper() const;
  301. String to_lower() const;
  302. int count(const String &p_string, int p_from = 0, int p_to = 0) const;
  303. int countn(const String &p_string, int p_from = 0, int p_to = 0) const;
  304. String left(int p_len) const;
  305. String right(int p_len) const;
  306. String indent(const String &p_prefix) const;
  307. String dedent() const;
  308. String strip_edges(bool left = true, bool right = true) const;
  309. String strip_escapes() const;
  310. String lstrip(const String &p_chars) const;
  311. String rstrip(const String &p_chars) const;
  312. String get_extension() const;
  313. String get_basename() const;
  314. String path_join(const String &p_file) const;
  315. char32_t unicode_at(int p_idx) const;
  316. CharString ascii(bool p_allow_extended = false) const;
  317. CharString utf8() const;
  318. Error parse_utf8(const char *p_utf8, int p_len = -1, bool p_skip_cr = false);
  319. static String utf8(const char *p_utf8, int p_len = -1);
  320. Char16String utf16() const;
  321. Error parse_utf16(const char16_t *p_utf16, int p_len = -1);
  322. static String utf16(const char16_t *p_utf16, int p_len = -1);
  323. static uint32_t hash(const char32_t *p_cstr, int p_len); /* hash the string */
  324. static uint32_t hash(const char32_t *p_cstr); /* hash the string */
  325. static uint32_t hash(const wchar_t *p_cstr, int p_len); /* hash the string */
  326. static uint32_t hash(const wchar_t *p_cstr); /* hash the string */
  327. static uint32_t hash(const char *p_cstr, int p_len); /* hash the string */
  328. static uint32_t hash(const char *p_cstr); /* hash the string */
  329. uint32_t hash() const; /* hash the string */
  330. uint64_t hash64() const; /* hash the string */
  331. String md5_text() const;
  332. String sha1_text() const;
  333. String sha256_text() const;
  334. Vector<uint8_t> md5_buffer() const;
  335. Vector<uint8_t> sha1_buffer() const;
  336. Vector<uint8_t> sha256_buffer() const;
  337. _FORCE_INLINE_ bool is_empty() const { return length() == 0; }
  338. _FORCE_INLINE_ bool contains(const char *p_str) const { return find(p_str) != -1; }
  339. _FORCE_INLINE_ bool contains(const String &p_str) const { return find(p_str) != -1; }
  340. // path functions
  341. bool is_absolute_path() const;
  342. bool is_relative_path() const;
  343. bool is_resource_file() const;
  344. String path_to(const String &p_path) const;
  345. String path_to_file(const String &p_path) const;
  346. String get_base_dir() const;
  347. String get_file() const;
  348. static String humanize_size(uint64_t p_size);
  349. String simplify_path() const;
  350. bool is_network_share_path() const;
  351. String xml_escape(bool p_escape_quotes = false) const;
  352. String xml_unescape() const;
  353. String uri_encode() const;
  354. String uri_decode() const;
  355. String c_escape() const;
  356. String c_escape_multiline() const;
  357. String c_unescape() const;
  358. String json_escape() const;
  359. Error parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const;
  360. String property_name_encode() const;
  361. // node functions
  362. static String get_invalid_node_name_characters();
  363. String validate_node_name() const;
  364. String validate_identifier() const;
  365. String validate_filename() const;
  366. bool is_valid_identifier() const;
  367. bool is_valid_int() const;
  368. bool is_valid_float() const;
  369. bool is_valid_hex_number(bool p_with_prefix) const;
  370. bool is_valid_html_color() const;
  371. bool is_valid_ip_address() const;
  372. bool is_valid_filename() const;
  373. /**
  374. * The constructors must not depend on other overloads
  375. */
  376. _FORCE_INLINE_ String() {}
  377. _FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
  378. _FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); }
  379. Vector<uint8_t> to_ascii_buffer() const;
  380. Vector<uint8_t> to_utf8_buffer() const;
  381. Vector<uint8_t> to_utf16_buffer() const;
  382. Vector<uint8_t> to_utf32_buffer() const;
  383. Vector<uint8_t> to_wchar_buffer() const;
  384. String(const char *p_str);
  385. String(const wchar_t *p_str);
  386. String(const char32_t *p_str);
  387. String(const char *p_str, int p_clip_to_len);
  388. String(const wchar_t *p_str, int p_clip_to_len);
  389. String(const char32_t *p_str, int p_clip_to_len);
  390. String(const StrRange &p_range);
  391. };
  392. bool operator==(const char *p_chr, const String &p_str);
  393. bool operator==(const wchar_t *p_chr, const String &p_str);
  394. bool operator!=(const char *p_chr, const String &p_str);
  395. bool operator!=(const wchar_t *p_chr, const String &p_str);
  396. String operator+(const char *p_chr, const String &p_str);
  397. String operator+(const wchar_t *p_chr, const String &p_str);
  398. String operator+(char32_t p_chr, const String &p_str);
  399. String itos(int64_t p_val);
  400. String uitos(uint64_t p_val);
  401. String rtos(double p_val);
  402. String rtoss(double p_val); //scientific version
  403. struct NoCaseComparator {
  404. bool operator()(const String &p_a, const String &p_b) const {
  405. return p_a.nocasecmp_to(p_b) < 0;
  406. }
  407. };
  408. struct NaturalNoCaseComparator {
  409. bool operator()(const String &p_a, const String &p_b) const {
  410. return p_a.naturalnocasecmp_to(p_b) < 0;
  411. }
  412. };
  413. template <typename L, typename R>
  414. _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
  415. while (true) {
  416. const char32_t l = *l_ptr;
  417. const char32_t r = *r_ptr;
  418. if (l == 0 && r == 0) {
  419. return false;
  420. } else if (l == 0) {
  421. return true;
  422. } else if (r == 0) {
  423. return false;
  424. } else if (l < r) {
  425. return true;
  426. } else if (l > r) {
  427. return false;
  428. }
  429. l_ptr++;
  430. r_ptr++;
  431. }
  432. }
  433. /* end of namespace */
  434. // Tool translate (TTR and variants) for the editor UI,
  435. // and doc translate for the class reference (DTR).
  436. #ifdef TOOLS_ENABLED
  437. // Gets parsed.
  438. String TTR(const String &p_text, const String &p_context = "");
  439. String TTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
  440. String DTR(const String &p_text, const String &p_context = "");
  441. String DTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
  442. // Use for C strings.
  443. #define TTRC(m_value) (m_value)
  444. // Use to avoid parsing (for use later with C strings).
  445. #define TTRGET(m_value) TTR(m_value)
  446. #else
  447. #define TTRC(m_value) (m_value)
  448. #define TTRGET(m_value) (m_value)
  449. #endif
  450. // Use this to mark property names for editor translation.
  451. // Often for dynamic properties defined in _get_property_list().
  452. // Property names defined directly inside EDITOR_DEF, GLOBAL_DEF, and ADD_PROPERTY macros don't need this.
  453. #define PNAME(m_value) (m_value)
  454. // Similar to PNAME, but to mark groups, i.e. properties with PROPERTY_USAGE_GROUP.
  455. // Groups defined directly inside ADD_GROUP macros don't need this.
  456. // The arguments are the same as ADD_GROUP. m_prefix is only used for extraction.
  457. #define GNAME(m_value, m_prefix) (m_value)
  458. // Runtime translate for the public node API.
  459. String RTR(const String &p_text, const String &p_context = "");
  460. String RTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
  461. bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end);
  462. _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) {
  463. }
  464. _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str) {
  465. arr.push_back(p_str);
  466. }
  467. template <class... P>
  468. _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str, P... p_args) {
  469. arr.push_back(p_str);
  470. sarray_add_str(arr, p_args...);
  471. }
  472. template <class... P>
  473. _FORCE_INLINE_ Vector<String> sarray(P... p_args) {
  474. Vector<String> arr;
  475. sarray_add_str(arr, p_args...);
  476. return arr;
  477. }
  478. #endif // USTRING_GODOT_H