String.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2021-07-08
  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 ls_std::Class, public ls_std::IBoxing, public ls_std::ISerializable, public ls_std::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<ls_std::ISerializable> _serializable);
  63. void setStorable(std::shared_ptr<ls_std::IStorable> _storable);
  64. bool startsWith(const std::string &_text);
  65. std::string toLowerCase();
  66. std::string toUpperCase();
  67. private:
  68. std::shared_ptr<ls_std::ISerializable> serializable{};
  69. std::shared_ptr<ls_std::IStorable> storable{};
  70. std::string value{};
  71. void _assignSerializable(const std::shared_ptr<ls_std::ISerializable>& _serializable);
  72. void _assignStorable(const std::shared_ptr<ls_std::IStorable>& _storable);
  73. static std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  74. static std::string _createFillContent(const std::string &_text, size_t _width, char _fillCharacter);
  75. };
  76. }
  77. #endif