String.hpp 3.0 KB

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