String.hpp 4.4 KB

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