String.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2021-07-12
  7. *
  8. * */
  9. #ifndef LS_STD_STRING_HPP
  10. #define LS_STD_STRING_HPP
  11. #include "IBoxing.hpp"
  12. #include <ls_std/base/Class.hpp>
  13. #include <ls_std/base/Types.hpp>
  14. #include <string>
  15. #include <memory>
  16. #include <vector>
  17. namespace ls_std
  18. {
  19. class String : public ls_std::Class, public ls_std::IBoxing
  20. {
  21. public:
  22. String();
  23. explicit String(std::string _value);
  24. ~String() override = default;
  25. // conversion operator
  26. operator const char *() const; // do not make explicit!
  27. operator std::string() const; // do not make explicit!
  28. // assignment operators
  29. ls_std::String &operator=(std::string _value);
  30. // arithmetic operators
  31. std::string operator+(ls_std::String _string) const;
  32. std::string operator+(const std::string &_string) const;
  33. std::string operator+(const char *_string) const;
  34. std::string operator-(int _number);
  35. // compound operators
  36. ls_std::String &operator+=(ls_std::String _string);
  37. ls_std::String &operator+=(const std::string &_text);
  38. // comparison operators
  39. bool operator==(ls_std::String _string);
  40. bool operator==(const std::string &_value);
  41. bool operator==(const char *_value);
  42. bool operator!=(ls_std::String _string);
  43. bool operator!=(const std::string &_value);
  44. bool operator!=(const char *_value);
  45. // implementation
  46. void parse(std::string _parseText) override;
  47. std::string toString() override;
  48. // additional functionality
  49. bool contains(const std::string &_text);
  50. bool endsWith(const std::string &_text);
  51. bool equalsIgnoreCase(ls_std::String _string);
  52. bool equalsIgnoreCase(std::string _text);
  53. std::vector<ls_std::byte> getByteData();
  54. std::string padLeft(size_t _width, char _fillCharacter);
  55. std::string padRight(size_t _width, char _fillCharacter);
  56. std::string reverse();
  57. bool startsWith(const std::string &_text);
  58. std::string toLowerCase();
  59. std::string toUpperCase();
  60. private:
  61. std::string value{};
  62. static std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  63. static std::string _createFillContent(const std::string &_text, size_t _width, char _fillCharacter);
  64. };
  65. }
  66. #endif