aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/uri/encodefsm.rl6
blob: 3a5d90a98d2881fe5af4a34d00a50ce178b0c7a8 (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;
}

}
}