RfcString.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef _RFCSTRING_H
  2. #define _RFCSTRING_H 1
  3. namespace bd {
  4. class String;
  5. }
  6. #include "rfc1459.h"
  7. #include <bdlib/src/String.h>
  8. class RfcString : public bd::String {
  9. private:
  10. protected:
  11. public:
  12. using String::String;
  13. RfcString(const String &str) : String(str) {};
  14. RfcString(String &&str) : String(std::move(str)) {};
  15. int compare(const RfcString& str, size_t n = npos) const noexcept
  16. __attribute__((pure));
  17. friend bool operator==(const RfcString&, const RfcString&);
  18. friend bool operator!=(const RfcString&, const RfcString&);
  19. friend bool operator<(const RfcString&, const RfcString&);
  20. friend bool operator<=(const RfcString&, const RfcString&);
  21. friend bool operator>(const RfcString&, const RfcString&);
  22. friend bool operator>=(const RfcString&, const RfcString&);
  23. virtual size_t hash() const noexcept;
  24. };
  25. inline bool __attribute__((pure))
  26. operator==(const RfcString& lhs, const RfcString& rhs) {
  27. return (lhs.length() == rhs.length() &&
  28. lhs.compare(rhs) == 0);
  29. }
  30. inline bool __attribute__((pure))
  31. operator!=(const RfcString& lhs, const RfcString& rhs) {
  32. return ! (lhs == rhs);
  33. }
  34. inline bool __attribute__((pure))
  35. operator<(const RfcString& lhs, const RfcString& rhs) {
  36. return (lhs.compare(rhs) < 0);
  37. }
  38. inline bool __attribute__((pure))
  39. operator<=(const RfcString& lhs, const RfcString& rhs) {
  40. return ! (rhs < lhs);
  41. }
  42. inline bool __attribute__((pure))
  43. operator>(const RfcString& lhs, const RfcString& rhs) {
  44. return (rhs < lhs);
  45. }
  46. inline bool __attribute__((pure))
  47. operator>=(const RfcString& lhs, const RfcString& rhs) {
  48. return ! (lhs < rhs);
  49. }
  50. namespace std {
  51. template<>
  52. struct hash<RfcString>
  53. {
  54. inline size_t operator()(const RfcString& val) const {
  55. return val.hash();
  56. }
  57. };
  58. }
  59. #endif