String.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "String.hpp"
  2. #include "NodePath.hpp"
  3. namespace godot {
  4. #include <godot/godot_string.h>
  5. #include <string.h>
  6. godot::String::String()
  7. {
  8. godot_string_new(&_godot_string);
  9. }
  10. String::String(const char *contents)
  11. {
  12. godot_string_new_data(&_godot_string, contents, strlen(contents));
  13. }
  14. String::String(const wchar_t *contents)
  15. {
  16. // @Todo
  17. // godot_string_new_data(&_godot_string, contents, strlen(contents));
  18. godot_string_new(&_godot_string);
  19. }
  20. String::String(const wchar_t c)
  21. {
  22. // @Todo
  23. godot_string_new(&_godot_string);
  24. }
  25. String::String(const String& other)
  26. {
  27. godot_string_new(&_godot_string);
  28. godot_string_copy_string(&_godot_string, &other._godot_string);
  29. }
  30. String::~String()
  31. {
  32. godot_string_destroy(&_godot_string);
  33. }
  34. String String::substr(int p_from,int p_chars) const
  35. {
  36. return String(); // @Todo
  37. }
  38. wchar_t &String::operator [](const int idx)
  39. {
  40. return *godot_string_operator_index(&_godot_string, idx);
  41. }
  42. wchar_t String::operator [](const int idx) const
  43. {
  44. return *godot_string_operator_index((godot_string *) &_godot_string, idx);
  45. }
  46. int String::length() const
  47. {
  48. int len = 0;
  49. godot_string_get_data(&_godot_string, nullptr, &len);
  50. return len;
  51. }
  52. void String::operator =(const String &s)
  53. {
  54. godot_string_copy_string(&_godot_string, &s._godot_string);
  55. }
  56. bool String::operator ==(const String &s)
  57. {
  58. return godot_string_operator_equal(&_godot_string, &s._godot_string);
  59. }
  60. bool String::operator !=(const String &s)
  61. {
  62. return !(*this == s);
  63. }
  64. String String::operator +(const String &s)
  65. {
  66. String new_string;
  67. godot_string_operator_plus(&new_string._godot_string, &_godot_string, &s._godot_string);
  68. return new_string;
  69. }
  70. void String::operator +=(const String &s)
  71. {
  72. godot_string_operator_plus(&_godot_string, &_godot_string, &s._godot_string);
  73. }
  74. void String::operator +=(const wchar_t c)
  75. {
  76. // @Todo
  77. }
  78. bool String::operator <(const String &s)
  79. {
  80. return godot_string_operator_less(&_godot_string, &s._godot_string);
  81. }
  82. bool String::operator <=(const String &s)
  83. {
  84. return godot_string_operator_less(&_godot_string, &s._godot_string) || (*this == s);
  85. }
  86. bool String::operator >(const String &s)
  87. {
  88. return !(*this <= s);
  89. }
  90. bool String::operator >=(const String &s)
  91. {
  92. return !(*this < s);
  93. }
  94. String::operator NodePath() const
  95. {
  96. return NodePath(*this);
  97. }
  98. const char *String::c_string() const
  99. {
  100. return godot_string_c_str(&_godot_string);
  101. }
  102. String operator +(const char *a, const String& b)
  103. {
  104. return String(a) + b;
  105. }
  106. }