String.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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-31
  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/definition.hpp>
  13. #include <ls-std/core/interface/IBoxing.hpp>
  14. #include <ls-std/core/type/Types.hpp>
  15. #include <string>
  16. #include <string_view>
  17. #include <vector>
  18. namespace ls::std::boxing
  19. {
  20. ls_std_class String final : public core::Class, public core::interface_type::IBoxing
  21. {
  22. public:
  23. String();
  24. explicit String(::std::string _value);
  25. ~String() noexcept override;
  26. // assignment operators
  27. String &operator=(::std::string _value);
  28. // arithmetic operators
  29. ::std::string operator+(String _string) const;
  30. ::std::string operator+(const ::std::string &_string) const;
  31. ::std::string operator+(const char *_string) const;
  32. ::std::string operator-(int _number) const;
  33. // compound operators
  34. String &operator+=(String _string);
  35. String &operator+=(const ::std::string &_text);
  36. // comparison operators
  37. bool operator==(String _string) const;
  38. bool operator==(::std::string_view _value) const;
  39. bool operator==(const char *_value) const;
  40. bool operator!=(String _string) const;
  41. bool operator!=(::std::string_view _value) const;
  42. bool operator!=(const char *_value) const;
  43. // implementation
  44. void parse(const ::std::string &_parseText) override;
  45. [[nodiscard]] ::std::string toString() override;
  46. // additional functionality
  47. [[nodiscard]] bool contains(::std::string_view _text) const;
  48. [[nodiscard]] bool endsWith(::std::string_view _text) const;
  49. [[nodiscard]] bool equalsIgnoreCase(const String &_string) const;
  50. [[nodiscard]] bool equalsIgnoreCase(::std::string _text) const;
  51. [[nodiscard]] ::std::vector<core::type::byte_type> getByteData();
  52. [[nodiscard]] ::std::string padLeft(size_t _width, char _fillCharacter) const;
  53. [[nodiscard]] ::std::string padRight(size_t _width, char _fillCharacter) const;
  54. [[nodiscard]] ::std::string reverse() const;
  55. [[nodiscard]] bool startsWith(::std::string_view _text) const;
  56. [[nodiscard]] ::std::string toLowerCase() const;
  57. [[nodiscard]] ::std::string toUpperCase() const;
  58. private:
  59. ::std::string value{};
  60. [[nodiscard]] static ::std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  61. [[nodiscard]] static ::std::string _createFillContent(::std::string_view _text, size_t _width, char _fillCharacter);
  62. };
  63. }
  64. #endif