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