String.hpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2022-06-29
  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
  19. {
  20. namespace std
  21. {
  22. namespace boxing
  23. {
  24. class DYNAMIC_GOAL String : public ls::std::core::Class, public ls::std::core::interface_type::IBoxing
  25. {
  26. public:
  27. String();
  28. explicit String(::std::string _value);
  29. ~String() override = default;
  30. // conversion operator
  31. operator const char *() const; // do not make explicit!
  32. operator ::std::string() const; // do not make explicit!
  33. // assignment operators
  34. ls::std::boxing::String &operator=(::std::string _value);
  35. // arithmetic operators
  36. ::std::string operator+(ls::std::boxing::String _string) const;
  37. ::std::string operator+(const ::std::string &_string) const;
  38. ::std::string operator+(const char *_string) const;
  39. ::std::string operator-(int _number);
  40. // compound operators
  41. ls::std::boxing::String &operator+=(ls::std::boxing::String _string);
  42. ls::std::boxing::String &operator+=(const ::std::string &_text);
  43. // comparison operators
  44. bool operator==(ls::std::boxing::String _string);
  45. bool operator==(const ::std::string &_value);
  46. bool operator==(const char *_value);
  47. bool operator!=(ls::std::boxing::String _string);
  48. bool operator!=(const ::std::string &_value);
  49. bool operator!=(const char *_value);
  50. // implementation
  51. void parse(::std::string _parseText) override;
  52. ::std::string toString() override;
  53. // additional functionality
  54. bool contains(const ::std::string &_text);
  55. bool endsWith(const ::std::string &_text);
  56. bool equalsIgnoreCase(ls::std::boxing::String _string);
  57. bool equalsIgnoreCase(::std::string _text);
  58. ::std::vector<ls::std::core::type::byte> getByteData();
  59. ::std::string padLeft(size_t _width, char _fillCharacter);
  60. ::std::string padRight(size_t _width, char _fillCharacter);
  61. ::std::string reverse();
  62. bool startsWith(const ::std::string &_text);
  63. ::std::string toLowerCase();
  64. ::std::string toUpperCase();
  65. private:
  66. ::std::string value{};
  67. static ::std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  68. static ::std::string _createFillContent(const ::std::string &_text, size_t _width, char _fillCharacter);
  69. };
  70. }
  71. }
  72. }
  73. #endif