ustring.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. void copy_from(const char *p_cstr);
  154. void copy_from(const char *p_cstr, const int p_clip_to);
  155. void copy_from(const wchar_t *p_cstr);
  156. void copy_from(const wchar_t *p_cstr, const int p_clip_to);
  157. void copy_from(const char32_t *p_cstr);
  158. void copy_from(const char32_t *p_cstr, const int p_clip_to);
  159. void copy_from(const char32_t &p_char);
  160. void copy_from_unchecked(const char32_t *p_char, const int p_length);
  161. bool _base_is_subsequence_of(const String &p_string, bool case_insensitive) const;
  162. int _count(const String &p_string, int p_from, int p_to, bool p_case_insensitive) const;
  163. String _camelcase_to_underscore() const;
  164. public:
  165. enum {
  166. npos = -1 ///<for "some" compatibility with std::string (npos is a huge value in std::string)
  167. };
  168. _FORCE_INLINE_ char32_t *ptrw() { return _cowdata.ptrw(); }
  169. _FORCE_INLINE_ const char32_t *ptr() const { return _cowdata.ptr(); }
  170. void remove_at(int p_index) { _cowdata.remove_at(p_index); }
  171. _FORCE_INLINE_ void clear() { resize(0); }
  172. _FORCE_INLINE_ char32_t get(int p_index) const { return _cowdata.get(p_index); }
  173. _FORCE_INLINE_ void set(int p_index, const char32_t &p_elem) { _cowdata.set(p_index, p_elem); }
  174. _FORCE_INLINE_ int size() const { return _cowdata.size(); }
  175. Error resize(int p_size) { return _cowdata.resize(p_size); }
  176. _FORCE_INLINE_ const char32_t &operator[](int p_index) const {
  177. if (unlikely(p_index == _cowdata.size())) {
  178. return _null;
  179. }
  180. return _cowdata.get(p_index);
  181. }
  182. _FORCE_INLINE_ CharProxy<char32_t> operator[](int p_index) { return CharProxy<char32_t>(p_index, _cowdata); }
  183. bool operator==(const String &p_str) const;
  184. bool operator!=(const String &p_str) const;
  185. String operator+(const String &p_str) const;
  186. String operator+(char32_t p_char) const;
  187. String &operator+=(const String &);
  188. String &operator+=(char32_t p_char);
  189. String &operator+=(const char *p_str);
  190. String &operator+=(const wchar_t *p_str);
  191. String &operator+=(const char32_t *p_str);
  192. /* Compatibility Operators */
  193. void operator=(const char *p_str);
  194. void operator=(const wchar_t *p_str);
  195. void operator=(const char32_t *p_str);
  196. bool operator==(const char *p_str) const;
  197. bool operator==(const wchar_t *p_str) const;
  198. bool operator==(const char32_t *p_str) const;
  199. bool operator==(const StrRange &p_str_range) const;
  200. bool operator!=(const char *p_str) const;
  201. bool operator!=(const wchar_t *p_str) const;
  202. bool operator!=(const char32_t *p_str) const;
  203. bool operator<(const char32_t *p_str) const;
  204. bool operator<(const char *p_str) const;
  205. bool operator<(const wchar_t *p_str) const;
  206. bool operator<(const String &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. signed char casecmp_to(const String &p_str) const;
  211. signed char nocasecmp_to(const String &p_str) const;
  212. signed char naturalnocasecmp_to(const String &p_str) const;
  213. const char32_t *get_data() const;
  214. /* standard size stuff */
  215. _FORCE_INLINE_ int length() const {
  216. int s = size();
  217. return s ? (s - 1) : 0; // length does not include zero
  218. }
  219. bool is_valid_string() const;
  220. /* debug, error messages */
  221. void print_unicode_error(const String &p_message, bool p_critical = false) const;
  222. /* complex helpers */
  223. String substr(int p_from, int p_chars = -1) const;
  224. int find(const String &p_str, int p_from = 0) const; ///< return <0 if failed
  225. int find(const char *p_str, int p_from = 0) const; ///< return <0 if failed
  226. int find_char(const char32_t &p_char, int p_from = 0) const; ///< return <0 if failed
  227. int findn(const String &p_str, int p_from = 0) const; ///< return <0 if failed, case insensitive
  228. int rfind(const String &p_str, int p_from = -1) const; ///< return <0 if failed
  229. int rfindn(const String &p_str, int p_from = -1) const; ///< return <0 if failed, case insensitive
  230. int findmk(const Vector<String> &p_keys, int p_from = 0, int *r_key = nullptr) const; ///< return <0 if failed
  231. bool match(const String &p_wildcard) const;
  232. bool matchn(const String &p_wildcard) const;
  233. bool begins_with(const String &p_string) const;
  234. bool begins_with(const char *p_string) const;
  235. bool ends_with(const String &p_string) const;
  236. bool is_enclosed_in(const String &p_string) const;
  237. bool is_subsequence_of(const String &p_string) const;
  238. bool is_subsequence_ofn(const String &p_string) const;
  239. bool is_quoted() const;
  240. Vector<String> bigrams() const;
  241. float similarity(const String &p_string) const;
  242. String format(const Variant &values, String placeholder = "{_}") const;
  243. String replace_first(const String &p_key, const String &p_with) const;
  244. String replace(const String &p_key, const String &p_with) const;
  245. String replace(const char *p_key, const char *p_with) const;
  246. String replacen(const String &p_key, const String &p_with) const;
  247. String repeat(int p_count) const;
  248. String insert(int p_at_pos, const String &p_string) const;
  249. String pad_decimals(int p_digits) const;
  250. String pad_zeros(int p_digits) const;
  251. String trim_prefix(const String &p_prefix) const;
  252. String trim_suffix(const String &p_suffix) const;
  253. String lpad(int min_length, const String &character = " ") const;
  254. String rpad(int min_length, const String &character = " ") const;
  255. String sprintf(const Array &values, bool *error) const;
  256. String quote(String quotechar = "\"") const;
  257. String unquote() const;
  258. static String num(double p_num, int p_decimals = -1);
  259. static String num_scientific(double p_num);
  260. static String num_real(double p_num, bool p_trailing = true);
  261. static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
  262. static String num_uint64(uint64_t p_num, int base = 10, bool capitalize_hex = false);
  263. static String chr(char32_t p_char);
  264. static String md5(const uint8_t *p_md5);
  265. static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
  266. bool is_numeric() const;
  267. double to_float() const;
  268. int64_t hex_to_int() const;
  269. int64_t bin_to_int() const;
  270. int64_t to_int() const;
  271. static int64_t to_int(const char *p_str, int p_len = -1);
  272. static int64_t to_int(const wchar_t *p_str, int p_len = -1);
  273. static int64_t to_int(const char32_t *p_str, int p_len = -1, bool p_clamp = false);
  274. static double to_float(const char *p_str);
  275. static double to_float(const wchar_t *p_str, const wchar_t **r_end = nullptr);
  276. static double to_float(const char32_t *p_str, const char32_t **r_end = nullptr);
  277. String capitalize() const;
  278. String to_camel_case() const;
  279. String to_pascal_case() const;
  280. String to_snake_case() const;
  281. String get_with_code_lines() const;
  282. int get_slice_count(String p_splitter) const;
  283. String get_slice(String p_splitter, int p_slice) const;
  284. String get_slicec(char32_t p_splitter, int p_slice) const;
  285. Vector<String> split(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
  286. Vector<String> rsplit(const String &p_splitter = "", bool p_allow_empty = true, int p_maxsplit = 0) const;
  287. Vector<String> split_spaces() const;
  288. Vector<double> split_floats(const String &p_splitter, bool p_allow_empty = true) const;
  289. Vector<float> split_floats_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const;
  290. Vector<int> split_ints(const String &p_splitter, bool p_allow_empty = true) const;
  291. Vector<int> split_ints_mk(const Vector<String> &p_splitters, bool p_allow_empty = true) const;
  292. String join(Vector<String> parts) const;
  293. static char32_t char_uppercase(char32_t p_char);
  294. static char32_t char_lowercase(char32_t p_char);
  295. String to_upper() const;
  296. String to_lower() const;
  297. int count(const String &p_string, int p_from = 0, int p_to = 0) const;
  298. int countn(const String &p_string, int p_from = 0, int p_to = 0) const;
  299. String left(int p_len) const;
  300. String right(int p_len) const;
  301. String indent(const String &p_prefix) const;
  302. String dedent() const;
  303. String strip_edges(bool left = true, bool right = true) const;
  304. String strip_escapes() const;
  305. String lstrip(const String &p_chars) const;
  306. String rstrip(const String &p_chars) const;
  307. String get_extension() const;
  308. String get_basename() const;
  309. String path_join(const String &p_file) const;
  310. char32_t unicode_at(int p_idx) const;
  311. CharString ascii(bool p_allow_extended = false) const;
  312. CharString utf8() const;
  313. Error parse_utf8(const char *p_utf8, int p_len = -1, bool p_skip_cr = false);
  314. static String utf8(const char *p_utf8, int p_len = -1);
  315. Char16String utf16() const;
  316. Error parse_utf16(const char16_t *p_utf16, int p_len = -1);
  317. static String utf16(const char16_t *p_utf16, int p_len = -1);
  318. static uint32_t hash(const char32_t *p_cstr, int p_len); /* hash the string */
  319. static uint32_t hash(const char32_t *p_cstr); /* hash the string */
  320. static uint32_t hash(const wchar_t *p_cstr, int p_len); /* hash the string */
  321. static uint32_t hash(const wchar_t *p_cstr); /* hash the string */
  322. static uint32_t hash(const char *p_cstr, int p_len); /* hash the string */
  323. static uint32_t hash(const char *p_cstr); /* hash the string */
  324. uint32_t hash() const; /* hash the string */
  325. uint64_t hash64() const; /* hash the string */
  326. String md5_text() const;
  327. String sha1_text() const;
  328. String sha256_text() const;
  329. Vector<uint8_t> md5_buffer() const;
  330. Vector<uint8_t> sha1_buffer() const;
  331. Vector<uint8_t> sha256_buffer() const;
  332. _FORCE_INLINE_ bool is_empty() const { return length() == 0; }
  333. _FORCE_INLINE_ bool contains(const char *p_str) const { return find(p_str) != -1; }
  334. _FORCE_INLINE_ bool contains(const String &p_str) const { return find(p_str) != -1; }
  335. // path functions
  336. bool is_absolute_path() const;
  337. bool is_relative_path() const;
  338. bool is_resource_file() const;
  339. String path_to(const String &p_path) const;
  340. String path_to_file(const String &p_path) const;
  341. String get_base_dir() const;
  342. String get_file() const;
  343. static String humanize_size(uint64_t p_size);
  344. String simplify_path() const;
  345. bool is_network_share_path() const;
  346. String xml_escape(bool p_escape_quotes = false) const;
  347. String xml_unescape() const;
  348. String uri_encode() const;
  349. String uri_decode() const;
  350. String c_escape() const;
  351. String c_escape_multiline() const;
  352. String c_unescape() const;
  353. String json_escape() const;
  354. Error parse_url(String &r_scheme, String &r_host, int &r_port, String &r_path) const;
  355. String property_name_encode() const;
  356. // node functions
  357. static const String invalid_node_name_characters;
  358. String validate_node_name() const;
  359. String validate_identifier() const;
  360. String validate_filename() const;
  361. bool is_valid_identifier() const;
  362. bool is_valid_int() const;
  363. bool is_valid_float() const;
  364. bool is_valid_hex_number(bool p_with_prefix) const;
  365. bool is_valid_html_color() const;
  366. bool is_valid_ip_address() const;
  367. bool is_valid_filename() const;
  368. /**
  369. * The constructors must not depend on other overloads
  370. */
  371. _FORCE_INLINE_ String() {}
  372. _FORCE_INLINE_ String(const String &p_str) { _cowdata._ref(p_str._cowdata); }
  373. _FORCE_INLINE_ void operator=(const String &p_str) { _cowdata._ref(p_str._cowdata); }
  374. Vector<uint8_t> to_ascii_buffer() const;
  375. Vector<uint8_t> to_utf8_buffer() const;
  376. Vector<uint8_t> to_utf16_buffer() const;
  377. Vector<uint8_t> to_utf32_buffer() const;
  378. String(const char *p_str);
  379. String(const wchar_t *p_str);
  380. String(const char32_t *p_str);
  381. String(const char *p_str, int p_clip_to_len);
  382. String(const wchar_t *p_str, int p_clip_to_len);
  383. String(const char32_t *p_str, int p_clip_to_len);
  384. String(const StrRange &p_range);
  385. };
  386. bool operator==(const char *p_chr, const String &p_str);
  387. bool operator==(const wchar_t *p_chr, const String &p_str);
  388. bool operator!=(const char *p_chr, const String &p_str);
  389. bool operator!=(const wchar_t *p_chr, const String &p_str);
  390. String operator+(const char *p_chr, const String &p_str);
  391. String operator+(const wchar_t *p_chr, const String &p_str);
  392. String operator+(char32_t p_chr, const String &p_str);
  393. String itos(int64_t p_val);
  394. String uitos(uint64_t p_val);
  395. String rtos(double p_val);
  396. String rtoss(double p_val); //scientific version
  397. struct NoCaseComparator {
  398. bool operator()(const String &p_a, const String &p_b) const {
  399. return p_a.nocasecmp_to(p_b) < 0;
  400. }
  401. };
  402. struct NaturalNoCaseComparator {
  403. bool operator()(const String &p_a, const String &p_b) const {
  404. return p_a.naturalnocasecmp_to(p_b) < 0;
  405. }
  406. };
  407. template <typename L, typename R>
  408. _FORCE_INLINE_ bool is_str_less(const L *l_ptr, const R *r_ptr) {
  409. while (true) {
  410. const char32_t l = *l_ptr;
  411. const char32_t r = *r_ptr;
  412. if (l == 0 && r == 0) {
  413. return false;
  414. } else if (l == 0) {
  415. return true;
  416. } else if (r == 0) {
  417. return false;
  418. } else if (l < r) {
  419. return true;
  420. } else if (l > r) {
  421. return false;
  422. }
  423. l_ptr++;
  424. r_ptr++;
  425. }
  426. }
  427. /* end of namespace */
  428. // Tool translate (TTR and variants) for the editor UI,
  429. // and doc translate for the class reference (DTR).
  430. #ifdef TOOLS_ENABLED
  431. // Gets parsed.
  432. String TTR(const String &p_text, const String &p_context = "");
  433. String TTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
  434. String DTR(const String &p_text, const String &p_context = "");
  435. String DTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
  436. // Use for C strings.
  437. #define TTRC(m_value) (m_value)
  438. // Use to avoid parsing (for use later with C strings).
  439. #define TTRGET(m_value) TTR(m_value)
  440. #else
  441. #define TTRC(m_value) (m_value)
  442. #define TTRGET(m_value) (m_value)
  443. #endif
  444. // Use this to mark property names for editor translation.
  445. // Often for dynamic properties defined in _get_property_list().
  446. // Property names defined directly inside EDITOR_DEF, GLOBAL_DEF, and ADD_PROPERTY macros don't need this.
  447. #define PNAME(m_value) (m_value)
  448. // Similar to PNAME, but to mark groups, i.e. properties with PROPERTY_USAGE_GROUP.
  449. // Groups defined directly inside ADD_GROUP macros don't need this.
  450. // The arguments are the same as ADD_GROUP. m_prefix is only used for extraction.
  451. #define GNAME(m_value, m_prefix) (m_value)
  452. // Runtime translate for the public node API.
  453. String RTR(const String &p_text, const String &p_context = "");
  454. String RTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context = "");
  455. bool select_word(const String &p_s, int p_col, int &r_beg, int &r_end);
  456. _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr) {
  457. }
  458. _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str) {
  459. arr.push_back(p_str);
  460. }
  461. template <class... P>
  462. _FORCE_INLINE_ void sarray_add_str(Vector<String> &arr, const String &p_str, P... p_args) {
  463. arr.push_back(p_str);
  464. sarray_add_str(arr, p_args...);
  465. }
  466. template <class... P>
  467. _FORCE_INLINE_ Vector<String> sarray(P... p_args) {
  468. Vector<String> arr;
  469. sarray_add_str(arr, p_args...);
  470. return arr;
  471. }
  472. #endif // USTRING_GODOT_H