String.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #ifndef STRING_H
  2. #define STRING_H
  3. #include <gdnative/string.h>
  4. namespace godot {
  5. class NodePath;
  6. class Variant;
  7. class PoolByteArray;
  8. class PoolIntArray;
  9. class PoolRealArray;
  10. class PoolStringArray;
  11. class String;
  12. class CharString {
  13. friend class String;
  14. godot_char_string _char_string;
  15. public:
  16. ~CharString();
  17. int length() const;
  18. const char *get_data() const;
  19. };
  20. class String {
  21. godot_string _godot_string;
  22. friend class Dictionary;
  23. friend class NodePath;
  24. friend class Variant;
  25. explicit inline String(godot_string contents) :
  26. _godot_string(contents) {}
  27. public:
  28. String();
  29. String(const char *contents);
  30. String(const wchar_t *contents);
  31. String(const wchar_t c);
  32. String(const String &other);
  33. String(String &&other);
  34. ~String();
  35. static String num(double p_num, int p_decimals = -1);
  36. static String num_scientific(double p_num);
  37. static String num_real(double p_num);
  38. static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
  39. static String chr(godot_char_type p_char);
  40. static String md5(const uint8_t *p_md5);
  41. static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
  42. wchar_t &operator[](const int idx);
  43. wchar_t operator[](const int idx) const;
  44. void operator=(const String &s);
  45. void operator=(String &&s);
  46. bool operator==(const String &s) const;
  47. bool operator!=(const String &s) const;
  48. String operator+(const String &s) const;
  49. void operator+=(const String &s);
  50. void operator+=(const wchar_t c);
  51. bool operator<(const String &s) const;
  52. bool operator<=(const String &s) const;
  53. bool operator>(const String &s) const;
  54. bool operator>=(const String &s) const;
  55. operator NodePath() const;
  56. int length() const;
  57. const wchar_t *unicode_str() const;
  58. char *alloc_c_string() const;
  59. CharString utf8() const;
  60. CharString ascii(bool p_extended = false) const;
  61. bool begins_with(String &s) const;
  62. bool begins_with_char_array(const char *p_char_array) const;
  63. PoolStringArray bigrams() const;
  64. String c_escape() const;
  65. String c_unescape() const;
  66. String capitalize() const;
  67. bool empty() const;
  68. bool ends_with(String &text) const;
  69. void erase(int position, int chars);
  70. int find(String what, int from = 0) const;
  71. int find_last(String what) const;
  72. int findn(String what, int from = 0) const;
  73. String format(Variant values) const;
  74. String format(Variant values, String placeholder) const;
  75. String get_base_dir() const;
  76. String get_basename() const;
  77. String get_extension() const;
  78. String get_file() const;
  79. int hash() const;
  80. int hex_to_int() const;
  81. String insert(int position, String what) const;
  82. bool is_abs_path() const;
  83. bool is_rel_path() const;
  84. bool is_subsequence_of(String text) const;
  85. bool is_subsequence_ofi(String text) const;
  86. bool is_valid_float() const;
  87. bool is_valid_html_color() const;
  88. bool is_valid_identifier() const;
  89. bool is_valid_integer() const;
  90. bool is_valid_ip_address() const;
  91. String json_escape() const;
  92. String left(int position) const;
  93. bool match(String expr) const;
  94. bool matchn(String expr) const;
  95. PoolByteArray md5_buffer() const;
  96. String md5_text() const;
  97. int ord_at(int at) const;
  98. String pad_decimals(int digits) const;
  99. String pad_zeros(int digits) const;
  100. String percent_decode() const;
  101. String percent_encode() const;
  102. String plus_file(String file) const;
  103. String replace(String what, String forwhat) const;
  104. String replacen(String what, String forwhat) const;
  105. int rfind(String what, int from = -1) const;
  106. int rfindn(String what, int from = -1) const;
  107. String right(int position) const;
  108. PoolByteArray sha256_buffer() const;
  109. String sha256_text() const;
  110. float similarity(String text) const;
  111. PoolStringArray split(String divisor, bool allow_empty = true) const;
  112. PoolIntArray split_ints(String divisor, bool allow_empty = true) const;
  113. PoolRealArray split_floats(String divisor, bool allow_empty = true) const;
  114. String strip_edges(bool left = true, bool right = true) const;
  115. String substr(int from, int len) const;
  116. float to_float() const;
  117. int64_t to_int() const;
  118. String to_lower() const;
  119. String to_upper() const;
  120. String xml_escape() const;
  121. String xml_unescape() const;
  122. signed char casecmp_to(String p_str) const;
  123. signed char nocasecmp_to(String p_str) const;
  124. signed char naturalnocasecmp_to(String p_str) const;
  125. String dedent() const;
  126. PoolStringArray rsplit(const String &divisor, const bool allow_empty = true, const int maxsplit = 0) const;
  127. String rstrip(const String &chars) const;
  128. String trim_prefix(const String &prefix) const;
  129. String trim_suffix(const String &suffix) const;
  130. };
  131. String operator+(const char *a, const String &b);
  132. String operator+(const wchar_t *a, const String &b);
  133. } // namespace godot
  134. #endif // STRING_H