String.hpp 2.7 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: 2022-07-03
  7. *
  8. * */
  9. #ifndef LS_STD_STRING_HPP
  10. #define LS_STD_STRING_HPP
  11. #include <ls_std/core/interface/IBoxing.hpp>
  12. #include <ls_std/core/Class.hpp>
  13. #include <ls_std/core/types/Types.hpp>
  14. #include <string>
  15. #include <memory>
  16. #include <vector>
  17. #include <ls_std/os/dynamic_goal.hpp>
  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 = default;
  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. ::std::string toString() override;
  49. // additional functionality
  50. bool contains(const ::std::string &_text);
  51. bool endsWith(const ::std::string &_text);
  52. bool equalsIgnoreCase(ls::std::boxing::String _string);
  53. bool equalsIgnoreCase(::std::string _text);
  54. ::std::vector<ls::std::core::type::byte> getByteData();
  55. ::std::string padLeft(size_t _width, char _fillCharacter);
  56. ::std::string padRight(size_t _width, char _fillCharacter);
  57. ::std::string reverse();
  58. bool startsWith(const ::std::string &_text);
  59. ::std::string toLowerCase();
  60. ::std::string toUpperCase();
  61. private:
  62. ::std::string value{};
  63. static ::std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  64. static ::std::string _createFillContent(const ::std::string &_text, size_t _width, char _fillCharacter);
  65. };
  66. }
  67. #endif