string-inl.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #ifndef STRING_INL_H_
  3. #error "Direct inclusion of this file is not allowed, include string.h"
  4. // For the sake of sane code completion.
  5. #include "string.h"
  6. #endif
  7. #include <util/str_stl.h>
  8. namespace NYson {
  9. ////////////////////////////////////////////////////////////////////////////////
  10. namespace NDetail {
  11. template <typename TLeft, typename TRight>
  12. bool Equals(const TLeft& lhs, const TRight& rhs)
  13. {
  14. auto lhsNull = !lhs.operator bool();
  15. auto rhsNull = !rhs.operator bool();
  16. if (lhsNull != rhsNull) {
  17. return false;
  18. }
  19. if (lhsNull && rhsNull) {
  20. return true;
  21. }
  22. return
  23. lhs.AsStringBuf() == rhs.AsStringBuf() &&
  24. lhs.GetType() == rhs.GetType();
  25. }
  26. } // namespace NDetail
  27. inline bool operator == (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs)
  28. {
  29. return NDetail::Equals(lhs, rhs);
  30. }
  31. inline bool operator != (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs)
  32. {
  33. return !(lhs == rhs);
  34. }
  35. ////////////////////////////////////////////////////////////////////////////////
  36. } // namespace NYson
  37. //! A hasher for TYsonStringBuf
  38. template <>
  39. struct THash<NYson::TYsonStringBuf>
  40. {
  41. size_t operator () (const NYson::TYsonStringBuf& str) const
  42. {
  43. return THash<TStringBuf>()(str.AsStringBuf());
  44. }
  45. };