String.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2024-05-25
  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. /*
  20. * @class(name: 'String', package: 'boxing')
  21. * */
  22. namespace ls::std::boxing
  23. {
  24. class LS_STD_DYNAMIC_GOAL String : public ls::std::core::Class, public ls::std::core::interface_type::IBoxing
  25. {
  26. public:
  27. String();
  28. explicit String(::std::string _value);
  29. ~String() noexcept override;
  30. // assignment operators
  31. ls::std::boxing::String &operator=(::std::string _value);
  32. // arithmetic operators
  33. ::std::string operator+(ls::std::boxing::String _string) const;
  34. ::std::string operator+(const ::std::string &_string) const;
  35. ::std::string operator+(const char *_string) const;
  36. ::std::string operator-(int _number) const;
  37. // compound operators
  38. ls::std::boxing::String &operator+=(ls::std::boxing::String _string);
  39. ls::std::boxing::String &operator+=(const ::std::string &_text);
  40. // comparison operators
  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. bool operator!=(ls::std::boxing::String _string) const;
  45. bool operator!=(::std::string_view _value) const;
  46. bool operator!=(const char *_value) const;
  47. // implementation
  48. void parse(const ::std::string &_parseText) override;
  49. [[nodiscard]] ::std::string toString() override;
  50. // additional functionality
  51. [[nodiscard]] bool contains(::std::string_view _text) const;
  52. [[nodiscard]] bool endsWith(::std::string_view _text) const;
  53. [[nodiscard]] bool equalsIgnoreCase(const ls::std::boxing::String &_string) const;
  54. [[nodiscard]] bool equalsIgnoreCase(::std::string _text) const;
  55. [[nodiscard]] ::std::vector<ls::std::core::type::byte_type> getByteData();
  56. [[nodiscard]] ::std::string padLeft(size_t _width, char _fillCharacter) const;
  57. [[nodiscard]] ::std::string padRight(size_t _width, char _fillCharacter) const;
  58. [[nodiscard]] ::std::string reverse() const;
  59. [[nodiscard]] bool startsWith(::std::string_view _text) const;
  60. [[nodiscard]] ::std::string toLowerCase() const;
  61. [[nodiscard]] ::std::string toUpperCase() const;
  62. private:
  63. ::std::string value{};
  64. [[nodiscard]] static ::std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  65. [[nodiscard]] static ::std::string _createFillContent(::std::string_view _text, size_t _width, char _fillCharacter);
  66. };
  67. }
  68. #endif