String.hpp 4.5 KB

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