encodefsm.rl6 930 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <library/cpp/uri/encode.h>
  2. #ifdef __clang__
  3. #pragma clang diagnostic ignored "-Wunused-variable"
  4. #endif
  5. namespace NUri {
  6. namespace NEncode {
  7. %%{
  8. machine TEncoder;
  9. hex = (
  10. digit >{ HexDigit(fc); } |
  11. [A-F] >{ HexUpper(fc); } |
  12. [a-f] >{ HexLower(fc); }
  13. );
  14. escaped = ( "%" hex hex )
  15. > { HexReset(); }
  16. % { DoHex(); };
  17. bad_escaped = ( "%" hex )
  18. % {
  19. DoSym(*(fpc - 2));
  20. DoSym(*(fpc - 1));
  21. };
  22. sym = (any - bad_escaped - escaped) %{ DoSym(*(fpc - 1)); };
  23. main := ( escaped | bad_escaped | sym )**;
  24. write data;
  25. }%%
  26. ui64 TEncoder::ReEncode(const TStringBuf &url)
  27. {
  28. const char *p = url.data();
  29. const char *pe = p + url.length();
  30. const char *eof = pe;
  31. int cs;
  32. OutFlags = 0;
  33. %% write init;
  34. %% write exec;
  35. return OutFlags;
  36. }
  37. }
  38. }