diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/json/json_prettifier.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/json/json_prettifier.h')
-rw-r--r-- | library/cpp/json/json_prettifier.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/library/cpp/json/json_prettifier.h b/library/cpp/json/json_prettifier.h new file mode 100644 index 00000000000..27d611b0b43 --- /dev/null +++ b/library/cpp/json/json_prettifier.h @@ -0,0 +1,58 @@ +#pragma once + +#include "json_reader.h" + +#include <util/generic/ylimits.h> + +namespace NJson { + struct TJsonPrettifier { + bool Unquote = false; + ui8 Padding = 4; + bool SingleQuotes = false; + bool Compactify = false; + bool Strict = false; + bool NewUnquote = false; // use new unquote, may break old tests + ui32 MaxPaddingLevel = Max<ui32>(); + + static TJsonPrettifier Prettifier(bool unquote = false, ui8 padding = 4, bool singlequotes = false) { + TJsonPrettifier p; + p.Unquote = unquote; + p.Padding = padding; + p.SingleQuotes = singlequotes; + return p; + } + + static TJsonPrettifier Compactifier(bool unquote = false, bool singlequote = false) { + TJsonPrettifier p; + p.Unquote = unquote; + p.Padding = 0; + p.Compactify = true; + p.SingleQuotes = singlequote; + return p; + } + + bool Prettify(TStringBuf in, IOutputStream& out) const; + + TString Prettify(TStringBuf in) const; + + static bool MayUnquoteNew(TStringBuf in); + static bool MayUnquoteOld(TStringBuf in); + }; + + inline TString PrettifyJson(TStringBuf in, bool unquote = false, ui8 padding = 4, bool sq = false) { + return TJsonPrettifier::Prettifier(unquote, padding, sq).Prettify(in); + } + + inline bool PrettifyJson(TStringBuf in, IOutputStream& out, bool unquote = false, ui8 padding = 4, bool sq = false) { + return TJsonPrettifier::Prettifier(unquote, padding, sq).Prettify(in, out); + } + + inline bool CompactifyJson(TStringBuf in, IOutputStream& out, bool unquote = false, bool sq = false) { + return TJsonPrettifier::Compactifier(unquote, sq).Prettify(in, out); + } + + inline TString CompactifyJson(TStringBuf in, bool unquote = false, bool sq = false) { + return TJsonPrettifier::Compactifier(unquote, sq).Prettify(in); + } + +} |