String.hpp 2.8 KB

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