String.hpp 2.8 KB

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