String.hpp 2.2 KB

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