String.hpp 2.8 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: 2020-09-19
  7. *
  8. * */
  9. #ifndef LS_STD_STRING_HPP
  10. #define LS_STD_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. #include <vector>
  18. namespace ls_std {
  19. class String : public Class, public IBoxing, public ISerializable, public IStorable {
  20. public:
  21. String();
  22. explicit String(std::string _value);
  23. ~String() = default;
  24. // conversion operator
  25. operator const char*() const; // do not make explicit!
  26. operator std::string() const; // do not make explicit!
  27. // assignment operators
  28. String& operator=(std::string _value);
  29. // arithmetic operators
  30. std::string operator+(String _string) const;
  31. std::string operator+(const std::string& _string) const;
  32. std::string operator+(const char* _string) const;
  33. std::string operator-(int _number);
  34. // compound operators
  35. String& operator+=(String _string);
  36. String& operator+=(const std::string& _text);
  37. // comparison operators
  38. bool operator==(String _string);
  39. bool operator==(const std::string& _value);
  40. bool operator==(const char* _value);
  41. bool operator!=(String _string);
  42. bool operator!=(const std::string& _value);
  43. bool operator!=(const char* _value);
  44. // implementation
  45. ls_std::byte_field load() override;
  46. ls_std::byte_field marshal() override;
  47. void parse(std::string _parseText) override;
  48. void save(const ls_std::byte_field& _data) override;
  49. std::string toString() override;
  50. void unmarshal(const ls_std::byte_field& _data) override;
  51. // additional functionality
  52. bool contains(const std::string& _text);
  53. bool endsWith(const std::string& _text);
  54. bool equalsIgnoreCase(String _string);
  55. bool equalsIgnoreCase(std::string _text);
  56. std::vector<ls_std::byte> getByteData();
  57. std::string padLeft(size_t _width, char _fillCharacter);
  58. std::string padRight(size_t _width, char _fillCharacter);
  59. std::string reverse();
  60. void setSerializable(std::shared_ptr<ISerializable> _serializable);
  61. void setStorable(std::shared_ptr<IStorable> _storable);
  62. bool startsWith(const std::string& _text);
  63. std::string toLowerCase();
  64. std::string toUpperCase();
  65. private:
  66. std::shared_ptr<ISerializable> serializable {};
  67. std::shared_ptr<IStorable> storable {};
  68. std::string value {};
  69. static std::string _buildCharacterChain(size_t _amount, char _fillCharacter);
  70. static std::string _createFillContent(const std::string& _text, size_t _width, char _fillCharacter);
  71. };
  72. }
  73. #endif