String.hpp 3.9 KB

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