aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/unicode/set/unicode_set_token.h
blob: 6fa619f7574193d8be6d52f38c9aa84f36dd2765 (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
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include <util/generic/strbuf.h>
#include <util/generic/string.h>
#include <util/stream/output.h>

namespace NUnicode {
    namespace NPrivate {
        enum EUnicodeSetTokenType {
            USTT_EOS /* "eos" */,
            USTT_SYMBOL /* "symbol" */,
            USTT_QUOTED_PAIR /* "quoted-pair" */,
            USTT_CODEPOINT8 /* "codepoint8" */,
            USTT_CODEPOINT16 /* "codepoint16" */,
            USTT_CODEPOINT32 /* "codepoint32" */,
            USTT_CATEGORY /* "category" */,
            USTT_NEGATION /* "negation" */,
            USTT_RANGE /* "range" */,
            USTT_LBRACKET /* "lbracket" */,
            USTT_RBRACKET /* "rbracket" */,
        };

        struct TUnicodeSetToken {
            EUnicodeSetTokenType Type;
            wchar16 Symbol;
            TWtringBuf Data;

            explicit TUnicodeSetToken()
                : Type(USTT_EOS)
                , Symbol(0)
                , Data()
            {
            }

            explicit TUnicodeSetToken(EUnicodeSetTokenType tokenType)
                : Type(tokenType)
                , Symbol(0)
                , Data()
            {
            }

            explicit TUnicodeSetToken(EUnicodeSetTokenType tokenType, wchar16 symbol)
                : Type(tokenType)
                , Symbol(symbol)
                , Data()
            {
            }

            explicit TUnicodeSetToken(EUnicodeSetTokenType tokenType, const wchar16* dataBegin, size_t dataSize)
                : Type(tokenType)
                , Symbol(0)
                , Data(dataBegin, dataSize)
            {
            }
        };

    }
}

Y_DECLARE_OUT_SPEC(inline, NUnicode::NPrivate::TUnicodeSetToken, output, token) {
    output << token.Type;
    if (token.Symbol) {
        output << ":" << TUtf16String(1, token.Symbol).Quote();
    }
    if (!token.Data.empty()) {
        output << ":" << TUtf16String(token.Data).Quote();
    }
}