diff options
| author | finder <[email protected]> | 2022-02-10 16:49:24 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:49:24 +0300 | 
| commit | abbbaf4075fbaa0ff4ce9faa1188089466a21dbe (patch) | |
| tree | 4beaffe75727862ab08110c7ce520dc7aa49ff30 /library/cpp/json | |
| parent | 46f4bc6ab513a0ed1407f9095284a00e20f05adc (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/json')
| -rw-r--r-- | library/cpp/json/easy_parse/json_easy_parser.cpp | 96 | ||||
| -rw-r--r-- | library/cpp/json/easy_parse/json_easy_parser.h | 42 | ||||
| -rw-r--r-- | library/cpp/json/easy_parse/json_easy_parser_impl.h | 38 | ||||
| -rw-r--r-- | library/cpp/json/easy_parse/ya.make | 22 | ||||
| -rw-r--r-- | library/cpp/json/writer/json.cpp | 4 | 
5 files changed, 101 insertions, 101 deletions
| diff --git a/library/cpp/json/easy_parse/json_easy_parser.cpp b/library/cpp/json/easy_parse/json_easy_parser.cpp index 3c781f544bc..95eb59c7442 100644 --- a/library/cpp/json/easy_parse/json_easy_parser.cpp +++ b/library/cpp/json/easy_parse/json_easy_parser.cpp @@ -1,14 +1,14 @@ -#include "json_easy_parser.h" +#include "json_easy_parser.h"   #include <library/cpp/json/json_reader.h>  #include <util/string/cast.h> -#include <util/string/split.h> -#include <util/string/strip.h> - -namespace NJson { +#include <util/string/split.h>  +#include <util/string/strip.h>  +  +namespace NJson {       static TString MAP_IDENTIFIER = "{}";      static TString ARRAY_IDENTIFIER = "[]";      static TString ANY_IDENTIFIER = "*"; - +       static void ParsePath(TString path, TVector<TPathElem>* res) {          TVector<const char*> parts;          Split(path.begin(), '/', &parts); @@ -26,24 +26,24 @@ namespace NJson {                          arrayCounter = -1;                      }                      res->push_back(TPathElem(arrayCounter)); -                } -            } -        } -    } - +                }  +            }  +        }  +    }  +       void TJsonParser::AddField(const TString& path, bool nonEmpty) {          Fields.emplace_back();          Fields.back().NonEmpty = nonEmpty;          ParsePath(path, &Fields.back().Path);      } - +       TString TJsonParser::ConvertToTabDelimited(const TString& json) const {          TStringInput in(json);          TStringStream out;          ConvertToTabDelimited(in, out);          return out.Str();      } - +       class TRewriteJsonImpl: public NJson::TJsonCallbacks {          const TJsonParser& Parent;          TVector<TString> FieldValues; @@ -51,7 +51,7 @@ namespace NJson {          bool ShouldUpdateOnArrayChange;          int CurrentFieldIdx;          bool HasFormatError; - +       private:          static bool PathElementMatch(const TPathElem& templ, const TPathElem& real) {              if (templ.Type != real.Type) @@ -62,31 +62,31 @@ namespace NJson {                  return templ.Key == ANY_IDENTIFIER || templ.Key == real.Key;              return true;          } - +           bool CheckFilter(const TVector<TPathElem>& path) const {              if (Stack.size() < path.size()) -                return false; +                return false;               for (size_t n = 0; n < path.size(); ++n) {                  if (!PathElementMatch(path[n], Stack[n]))                      return false;              }              return true; -        } - +        }  +           void UpdateRule() {              for (size_t n = 0; n < Parent.Fields.size(); ++n) {                  if (FieldValues[n].empty() && CheckFilter(Parent.Fields[n].Path)) {                      CurrentFieldIdx = n;                      return;                  } -            } +            }               CurrentFieldIdx = -1; -        } - +        }  +           void Pop() {              Stack.pop_back();          } - +           void IncreaseArrayCounter() {              if (!Stack.empty() && Stack.back().Type == NImpl::ARRAY) {                  ++Stack.back().ArrayCounter; @@ -100,11 +100,11 @@ namespace NJson {              IncreaseArrayCounter();              if (CurrentFieldIdx >= 0) {                  FieldValues[CurrentFieldIdx] = ToString(val); -                UpdateRule(); +                UpdateRule();               }              return true; -        } - +        }  +       public:          TRewriteJsonImpl(const TJsonParser& parent)              : Parent(parent) @@ -117,8 +117,8 @@ namespace NJson {                  if (!Parent.Fields[n].Path.empty() && Parent.Fields[n].Path.back().Type == NImpl::ARRAY)                      ShouldUpdateOnArrayChange = true;              } -        } - +        }  +           bool OnOpenMap() override {              IncreaseArrayCounter();              Stack.push_back(TPathElem(NImpl::MAP)); @@ -127,8 +127,8 @@ namespace NJson {              else                  UpdateRule();              return true; -        } - +        }  +           bool OnOpenArray() override {              IncreaseArrayCounter();              Stack.push_back(TPathElem(-1)); @@ -144,17 +144,17 @@ namespace NJson {                  Pop();              if (!Stack.empty())                  Pop(); -            UpdateRule(); +            UpdateRule();               return true;          } - +           bool OnCloseArray() override {              if (!Stack.empty())                  Pop(); -            UpdateRule(); +            UpdateRule();               return true;          } - +           bool OnMapKey(const TStringBuf& key) override {              if (!Stack.empty() && Stack.back().Type == NImpl::MAP_KEY) {                  Pop(); @@ -167,23 +167,23 @@ namespace NJson {                  UpdateRule();              return true;          } - +           bool OnBoolean(bool b) override {              return OnValue(b);          } - +           bool OnInteger(long long i) override {              return OnValue(i); -        } - +        }  +           bool OnDouble(double f) override {              return OnValue(f);          } - +           bool OnString(const TStringBuf& str) override {              return OnValue(str);          } - +           bool IsOK() const {              if (HasFormatError)                  return false; @@ -192,17 +192,17 @@ namespace NJson {                      return false;              return true;          } - +           void WriteTo(IOutputStream& out) const {              for (size_t n = 0; n < FieldValues.size(); ++n)                  out << "\t" << FieldValues[n];          } - +           void WriteTo(TVector<TString>* res) const {              *res = FieldValues;          }      }; - +       void TJsonParser::ConvertToTabDelimited(IInputStream& in, IOutputStream& out) const {          TRewriteJsonImpl impl(*this);          ReadJson(&in, &impl); @@ -211,8 +211,8 @@ namespace NJson {              impl.WriteTo(out);              out.Flush();          } -    } - +    }  +       bool TJsonParser::Parse(const TString& json, TVector<TString>* res) const {          TRewriteJsonImpl impl(*this);          TStringInput in(json); @@ -222,8 +222,8 @@ namespace NJson {              return true;          } else              return false; -    } - +    }  +       //struct TTestMe {      //    TTestMe() {      //        TJsonParser worker; @@ -232,5 +232,5 @@ namespace NJson {      //        TString ret2 = worker.ConvertToTabDelimited(" [1, 2, 3, 4, 5] ");      //    }      //} testMe; - -} +  +}  diff --git a/library/cpp/json/easy_parse/json_easy_parser.h b/library/cpp/json/easy_parse/json_easy_parser.h index 59d7791ab14..64c483aabaf 100644 --- a/library/cpp/json/easy_parse/json_easy_parser.h +++ b/library/cpp/json/easy_parse/json_easy_parser.h @@ -1,12 +1,12 @@ -#pragma once +#pragma once   #include <util/generic/string.h> -#include <util/generic/vector.h> -#include <util/stream/input.h> -#include <util/stream/output.h> -#include "json_easy_parser_impl.h" - -namespace NJson { +#include <util/generic/vector.h>  +#include <util/stream/input.h>  +#include <util/stream/output.h>  +#include "json_easy_parser_impl.h"  +  +namespace NJson {       /* This class filters out nodes from a source JSON by a xpath-style description. It represent these nodes as a tab-delimited string (or a vector).       * It is useful if you need to parse a data which comes into JSON in a known and fixed format.       * Fields are set as a list of keys separated by slash, for example: @@ -21,26 +21,26 @@ namespace NJson {       * NB! Library can not extract values of not a simple type (namely it doesn't support the case when a result is a vocabulary or an array) from JSON.       * If you expect such a case, please check json_value.h.       */ - -    class TJsonParser { +  +    class TJsonParser {           TString Prefix; - -        struct TField { +  +        struct TField {               TVector<TPathElem> Path; -            bool NonEmpty; -        }; +            bool NonEmpty;  +        };           TVector<TField> Fields; - -        friend class TRewriteJsonImpl; - +  +        friend class TRewriteJsonImpl;  +           void ConvertToTabDelimited(IInputStream& in, IOutputStream& out) const; -    public: +    public:           void SetPrefix(const TString& prefix) { -            Prefix = prefix; -        } +            Prefix = prefix;  +        }           void AddField(const TString& path, bool mustExist);          TString ConvertToTabDelimited(const TString& json) const;          bool Parse(const TString& json, TVector<TString>* res) const; -    }; -} +    };  +}  diff --git a/library/cpp/json/easy_parse/json_easy_parser_impl.h b/library/cpp/json/easy_parse/json_easy_parser_impl.h index ec55d838b32..11941fb6d06 100644 --- a/library/cpp/json/easy_parse/json_easy_parser_impl.h +++ b/library/cpp/json/easy_parse/json_easy_parser_impl.h @@ -1,40 +1,40 @@ -#pragma once - +#pragma once  +   #include <util/generic/string.h> -namespace NJson { +namespace NJson {       namespace NImpl { -        enum EType { -            ARRAY, -            MAP, -            MAP_KEY -        }; +        enum EType {  +            ARRAY,  +            MAP,  +            MAP_KEY  +        };       }      template <class TStringType>      struct TPathElemImpl {          NImpl::EType Type;          TStringType Key; -        int ArrayCounter; - +        int ArrayCounter;  +           TPathElemImpl(NImpl::EType type)              : Type(type)              , ArrayCounter()          { -        } - +        }  +           TPathElemImpl(const TStringType& key)              : Type(NImpl::MAP_KEY)              , Key(key)              , ArrayCounter()          { -        } - -        TPathElemImpl(int arrayCounter) +        }  +  +        TPathElemImpl(int arrayCounter)               : Type(NImpl::ARRAY)              , ArrayCounter(arrayCounter)          { -        } -    }; - +        }  +    };  +       typedef TPathElemImpl<TString> TPathElem; -} +}  diff --git a/library/cpp/json/easy_parse/ya.make b/library/cpp/json/easy_parse/ya.make index 2304c542f24..d84feb7ff61 100644 --- a/library/cpp/json/easy_parse/ya.make +++ b/library/cpp/json/easy_parse/ya.make @@ -1,13 +1,13 @@ -OWNER(finder) - -LIBRARY() - +OWNER(finder)  +  +LIBRARY()  +   SRCS( -    json_easy_parser.cpp -) - -PEERDIR( +    json_easy_parser.cpp  +)  +  +PEERDIR(       library/cpp/json -) - -END() +)  +  +END()  diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index 02370c2d79e..7425b3b4bd9 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -2,7 +2,7 @@  #include <library/cpp/json/json_value.h> -#include <util/string/cast.h> +#include <util/string/cast.h>   #include <util/string/strspn.h>  #include <util/generic/algorithm.h>  #include <util/generic/ymath.h> @@ -263,7 +263,7 @@ namespace NJsonWriter {          UnsafeWriteValue(buf, len);          return TValueContext(*this);      } - +       TValueContext TBuf::WriteFloat(float f, EFloatToStringMode mode, int ndigits) {          return WriteFloatImpl(f, mode, ndigits);      } | 
