String.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2020-08-14
  6. * Changed: 2020-08-30
  7. *
  8. * */
  9. #ifndef STRING_HPP
  10. #define STRING_HPP
  11. #include "IBoxing.hpp"
  12. #include "../base/Class.hpp"
  13. #include "../serialization/ISerializable.hpp"
  14. #include "../io/IStorable.hpp"
  15. #include <string>
  16. #include <memory>
  17. namespace ls_std {
  18. class String : public Class, public IBoxing, public ISerializable, public IStorable {
  19. public:
  20. String();
  21. explicit String(std::string _value);
  22. ~String() = default;
  23. // conversion operator
  24. operator const char*() const; // do not make explicit!
  25. operator std::string() const; // do not make explicit!
  26. // assignment operators
  27. String& operator=(std::string _value);
  28. // arithmetic operators
  29. std::string operator+(String _string) const;
  30. std::string operator+(const std::string& _string) const;
  31. std::string operator+(const char* _string) const;
  32. std::string operator-(int _number);
  33. // compound operators
  34. String& operator+=(String _string);
  35. String& operator+=(const std::string& _text);
  36. // comparison operators
  37. bool operator==(String _string);
  38. bool operator==(const std::string& _value);
  39. bool operator==(const char* _value);
  40. bool operator!=(String _string);
  41. bool operator!=(const std::string& _value);
  42. bool operator!=(const char* _value);
  43. // implementation
  44. ls_std::byte_field load() override;
  45. ls_std::byte_field marshal() override;
  46. void parse(std::string _parseText) override;
  47. void save(const ls_std::byte_field& _data) override;
  48. std::string toString() override;
  49. void unmarshal(const ls_std::byte_field& _data) override;
  50. // additional functionality
  51. bool contains(const std::string& _text);
  52. bool endsWith(const std::string& _text);
  53. bool equalsIgnoreCase(String _string);
  54. bool equalsIgnoreCase(std::string _text);
  55. std::string padLeft(size_t _width, const char _fillCharacter);
  56. std::string padRight(size_t _width, const char _fillCharacter);
  57. std::string reverse();
  58. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  59. void setStorable(std::shared_ptr<IStorable> _storable);
  60. bool startsWith(const std::string& _text);
  61. std::string toLowerCase();
  62. std::string toUpperCase();
  63. private:
  64. std::shared_ptr<ISerializable> serializable {};
  65. std::shared_ptr<IStorable> storable {};
  66. std::string value {};
  67. static std::string _buildCharacterChain(size_t _amount, const char _fillCharacter);
  68. static std::string _createFillContent(const std::string& _text, size_t _width, const char _fillCharacter);
  69. };
  70. }
  71. #endif