String.hpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2021-04-23
  7. *
  8. * */
  9. #ifndef LS_STD_STRING_HPP
  10. #define LS_STD_STRING_HPP
  11. #include "IBoxing.hpp"
  12. #include <ls_std/base/Class.hpp>
  13. #include <ls_std/serialization/ISerializable.hpp>
  14. #include <ls_std/io/IStorable.hpp>
  15. #include <string>
  16. #include <memory>
  17. #include <vector>
  18. namespace ls_std
  19. {
  20. class String : public Class, public IBoxing, public ISerializable, public IStorable
  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::String &operator=(std::string _value);
  31. // arithmetic operators
  32. std::string operator+(ls_std::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::String &operator+=(ls_std::String _string);
  38. ls_std::String &operator+=(const std::string &_text);
  39. // comparison operators
  40. bool operator==(ls_std::String _string);
  41. bool operator==(const std::string &_value);
  42. bool operator==(const char *_value);
  43. bool operator!=(ls_std::String _string);
  44. bool operator!=(const std::string &_value);
  45. bool operator!=(const char *_value);
  46. // implementation
  47. ls_std::byte_field load() override;
  48. ls_std::byte_field marshal() override;
  49. void parse(std::string _parseText) override;
  50. void save(const ls_std::byte_field &_data) override;
  51. std::string toString() override;
  52. void unmarshal(const ls_std::byte_field &_data) override;
  53. // additional functionality
  54. bool contains(const std::string &_text);
  55. bool endsWith(const std::string &_text);
  56. bool equalsIgnoreCase(ls_std::String _string);
  57. bool equalsIgnoreCase(std::string _text);
  58. std::vector<ls_std::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. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  63. void setStorable(std::shared_ptr<IStorable> _storable);
  64. bool startsWith(const std::string &_text);
  65. std::string toLowerCase();
  66. std::string toUpperCase();
  67. private:
  68. std::shared_ptr<ISerializable> serializable{};
  69. std::shared_ptr<IStorable> storable{};
  70. std::string value{};
  71. static std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  72. static std::string _createFillContent(const std::string &_text, size_t _width, char _fillCharacter);
  73. };
  74. }
  75. #endif