String.hpp 2.5 KB

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