aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson/string-inl.h
blob: 92e9ab4531eb2242bb84ee487f17c9a435dcc969 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#ifndef STRING_INL_H_
#error "Direct inclusion of this file is not allowed, include string.h"
// For the sake of sane code completion.
#include "string.h"
#endif

#include <util/str_stl.h>

namespace NYson {

////////////////////////////////////////////////////////////////////////////////

namespace NDetail {

template <typename TLeft, typename TRight>
bool Equals(const TLeft& lhs, const TRight& rhs)
{
    auto lhsNull = !lhs.operator bool();
    auto rhsNull = !rhs.operator bool();
    if (lhsNull != rhsNull) {
        return false;
    }
    if (lhsNull && rhsNull) {
        return true;
    }
    return
        lhs.AsStringBuf() == rhs.AsStringBuf() &&
        lhs.GetType() == rhs.GetType();
}

} // namespace NDetail

inline bool operator == (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs)
{
    return NDetail::Equals(lhs, rhs);
}

inline bool operator != (const TYsonStringBuf& lhs, const TYsonStringBuf& rhs)
{
    return !(lhs == rhs);
}

////////////////////////////////////////////////////////////////////////////////

} // namespace NYson

//! A hasher for TYsonStringBuf
template <>
struct THash<NYson::TYsonStringBuf>
{
    size_t operator () (const NYson::TYsonStringBuf& str) const
    {
        return THash<TStringBuf>()(str.AsStringBuf());
    }
};