aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/uri/encodefsm.rl6
blob: 6a323aa85a3ea81897d7080c2c300e082a62e887 (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
#include <library/cpp/uri/encode.h>

#ifdef __clang__
    #pragma clang diagnostic ignored "-Wunused-variable"
#endif

namespace NUri {
namespace NEncode {

%%{
    machine TEncoder;

    hex = (
        digit >{ HexDigit(fc); } |
        [A-F] >{ HexUpper(fc); } |
        [a-f] >{ HexLower(fc); }
    );

    escaped = ( "%" hex hex )
            > { HexReset(); }
            % { DoHex(); };

    bad_escaped = ( "%" hex )
                % {
                      DoSym(*(fpc - 2));
                      DoSym(*(fpc - 1));
                  };

    sym = (any - bad_escaped - escaped) %{ DoSym(*(fpc - 1)); };

    main := ( escaped | bad_escaped | sym )**;

    write data;
}%%

ui64 TEncoder::ReEncode(const TStringBuf &url)
{
    const char *p  = url.data();
    const char *pe = p + url.length();
    const char *eof = pe;
    int cs;
    OutFlags = 0;

    %% write init;
    %% write exec;

    return OutFlags;
}

}
}