String.hpp 2.8 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: 2023-02-06
  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/types/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() override;
  26. // conversion operator
  27. operator const char *() const; // do not make explicit!
  28. operator ::std::string() const; // do not make explicit!
  29. // assignment operators
  30. ls::std::boxing::String &operator=(::std::string _value);
  31. // arithmetic operators
  32. ::std::string operator+(ls::std::boxing::String _string) const;
  33. ::std::string operator+(const ::std::string &_string) const;
  34. ::std::string operator+(const char *_string) const;
  35. ::std::string operator-(int _number);
  36. // compound operators
  37. ls::std::boxing::String &operator+=(ls::std::boxing::String _string);
  38. ls::std::boxing::String &operator+=(const ::std::string &_text);
  39. // comparison operators
  40. bool operator==(ls::std::boxing::String _string);
  41. bool operator==(const ::std::string &_value);
  42. bool operator==(const char *_value);
  43. bool operator!=(ls::std::boxing::String _string);
  44. bool operator!=(const ::std::string &_value);
  45. bool operator!=(const char *_value);
  46. // implementation
  47. void parse(::std::string _parseText) override;
  48. [[nodiscard]] ::std::string toString() override;
  49. // additional functionality
  50. [[nodiscard]] bool contains(const ::std::string &_text);
  51. [[nodiscard]] bool endsWith(const ::std::string &_text);
  52. [[nodiscard]] bool equalsIgnoreCase(ls::std::boxing::String _string);
  53. [[nodiscard]] bool equalsIgnoreCase(::std::string _text);
  54. [[nodiscard]] ::std::vector<ls::std::core::type::byte> getByteData();
  55. [[nodiscard]] ::std::string padLeft(size_t _width, char _fillCharacter);
  56. [[nodiscard]] ::std::string padRight(size_t _width, char _fillCharacter);
  57. [[nodiscard]] ::std::string reverse();
  58. [[nodiscard]] bool startsWith(const ::std::string &_text);
  59. [[nodiscard]] ::std::string toLowerCase();
  60. [[nodiscard]] ::std::string toUpperCase();
  61. private:
  62. ::std::string value{};
  63. [[nodiscard]] static ::std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  64. [[nodiscard]] static ::std::string _createFillContent(const ::std::string &_text, size_t _width, char _fillCharacter);
  65. };
  66. }
  67. #endif