unicode_set_token.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. #include <util/generic/string.h>
  4. #include <util/stream/output.h>
  5. namespace NUnicode {
  6. namespace NPrivate {
  7. enum EUnicodeSetTokenType {
  8. USTT_EOS /* "eos" */,
  9. USTT_SYMBOL /* "symbol" */,
  10. USTT_QUOTED_PAIR /* "quoted-pair" */,
  11. USTT_CODEPOINT8 /* "codepoint8" */,
  12. USTT_CODEPOINT16 /* "codepoint16" */,
  13. USTT_CODEPOINT32 /* "codepoint32" */,
  14. USTT_CATEGORY /* "category" */,
  15. USTT_NEGATION /* "negation" */,
  16. USTT_RANGE /* "range" */,
  17. USTT_LBRACKET /* "lbracket" */,
  18. USTT_RBRACKET /* "rbracket" */,
  19. };
  20. struct TUnicodeSetToken {
  21. EUnicodeSetTokenType Type;
  22. wchar16 Symbol;
  23. TWtringBuf Data;
  24. explicit TUnicodeSetToken()
  25. : Type(USTT_EOS)
  26. , Symbol(0)
  27. , Data()
  28. {
  29. }
  30. explicit TUnicodeSetToken(EUnicodeSetTokenType tokenType)
  31. : Type(tokenType)
  32. , Symbol(0)
  33. , Data()
  34. {
  35. }
  36. explicit TUnicodeSetToken(EUnicodeSetTokenType tokenType, wchar16 symbol)
  37. : Type(tokenType)
  38. , Symbol(symbol)
  39. , Data()
  40. {
  41. }
  42. explicit TUnicodeSetToken(EUnicodeSetTokenType tokenType, const wchar16* dataBegin, size_t dataSize)
  43. : Type(tokenType)
  44. , Symbol(0)
  45. , Data(dataBegin, dataSize)
  46. {
  47. }
  48. };
  49. }
  50. }
  51. Y_DECLARE_OUT_SPEC(inline, NUnicode::NPrivate::TUnicodeSetToken, output, token) {
  52. output << token.Type;
  53. if (token.Symbol) {
  54. output << ":" << TUtf16String(1, token.Symbol).Quote();
  55. }
  56. if (!token.Data.empty()) {
  57. output << ":" << TUtf16String(token.Data).Quote();
  58. }
  59. }