String.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2020-08-16
  7. *
  8. * */
  9. #include <algorithm>
  10. #include <utility>
  11. #include "String.hpp"
  12. ls_std::String::String() : Class("String")
  13. {}
  14. ls_std::String::String(std::string _value) : Class("String"),
  15. value(std::move(_value))
  16. {}
  17. ls_std::String::operator const char*() const {
  18. return this->value.c_str();
  19. }
  20. ls_std::String::operator std::string() const {
  21. return this->value;
  22. }
  23. ls_std::String & ls_std::String::operator=(std::string _value) {
  24. this->value = std::move(_value);
  25. return *this;
  26. }
  27. std::string ls_std::String::operator+(String _string) const {
  28. return this->value + _string.toString();
  29. }
  30. std::string ls_std::String::operator+(const std::string& _string) const {
  31. return this->value + _string;
  32. }
  33. std::string ls_std::String::operator+(const char *_string) const {
  34. return this->value + _string;
  35. }
  36. std::string ls_std::String::operator-(int _number) {
  37. std::string copy = this->value;
  38. return copy.substr(0, copy.size() - _number);
  39. }
  40. ls_std::String & ls_std::String::operator+=(String _string) {
  41. this->value = this->value + _string.toString();
  42. return *this;
  43. }
  44. ls_std::String & ls_std::String::operator+=(const std::string &_text) {
  45. this->value = this->value + _text;
  46. return *this;
  47. }
  48. bool ls_std::String::operator==(String _string) {
  49. return this->value == _string.toString();
  50. }
  51. bool ls_std::String::operator==(const std::string& _value) {
  52. return this->value == _value;
  53. }
  54. bool ls_std::String::operator==(const char *_value) {
  55. return this->value == _value;
  56. }
  57. bool ls_std::String::operator!=(String _string) {
  58. return this->value != _string.toString();
  59. }
  60. bool ls_std::String::operator!=(const std::string& _value) {
  61. return this->value != _value;
  62. }
  63. bool ls_std::String::operator!=(const char *_value) {
  64. return this->value != _value;
  65. }
  66. void ls_std::String::parse(std::string _parseText) {
  67. this->value = std::move(_parseText);
  68. }
  69. std::string ls_std::String::toString() {
  70. return this->value;
  71. }
  72. bool ls_std::String::contains(const std::string& _text) {
  73. return this->value.find(_text) != std::string::npos;
  74. }
  75. bool ls_std::String::endsWith(const std::string &_text) {
  76. return this->value.rfind(_text) == (this->value.size() - _text.size());
  77. }
  78. bool ls_std::String::equalsIgnoreCase(String _string) {
  79. return this->toLowerCase() == _string.toLowerCase();
  80. }
  81. bool ls_std::String::equalsIgnoreCase(std::string _text) {
  82. return this->toLowerCase() == ls_std::String{std::move(_text)}.toLowerCase();
  83. }
  84. std::string ls_std::String::reverse() {
  85. std::string copy = this->value;
  86. std::reverse(copy.begin(), copy.end());
  87. return copy;
  88. }
  89. bool ls_std::String::startsWith(const std::string &_text) {
  90. return this->value.rfind(_text, 0) == 0;
  91. }
  92. std::string ls_std::String::toLowerCase() {
  93. std::string copy = this->value;
  94. std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower);
  95. return copy;
  96. }
  97. std::string ls_std::String::toUpperCase() {
  98. std::string copy = this->value;
  99. std::transform(copy.begin(), copy.end(), copy.begin(), ::toupper);
  100. return copy;
  101. }