Lines Matching +full:back +full:- +full:end
1 //=== JSON.cpp - JSON value, parsing and serialization - C++ -----------*-===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===---------------------------------------------------------------------===//
25 return try_emplace(K, nullptr).first->getSecond();
28 return try_emplace(std::move(K), nullptr).first->getSecond();
32 if (I == end())
34 return &I->second;
38 if (I == end())
40 return &I->second;
44 return V->getAsNull();
49 return V->getAsBoolean();
54 return V->getAsNumber();
59 return V->getAsInteger();
64 return V->getAsString();
69 return V->getAsObject();
74 return V->getAsObject();
79 return V->getAsArray();
84 return V->getAsArray();
92 if (R == RHS.end() || L.second != R->second)
102 back().moveFrom(std::move(V));
196 // However we see 64-vs-80-bit precision comparisons with gcc-7 -O3 -m32.
215 for (P = this; P->Parent != nullptr; P = P->Parent)
217 Path::Root *R = P->Seg.root();
219 R->ErrorMessage = Msg;
220 R->ErrorPath.resize(Count);
221 auto It = R->ErrorPath.begin();
222 for (P = this; P->Parent != nullptr; P = P->Parent)
223 *It++ = P->Seg;
251 return L->first < R->first;
256 // Prints a one-line version of a value that isn't our main focus.
262 JOS.rawValue(V.getAsArray()->empty() ? "[]" : "[ ... ]");
265 JOS.rawValue(V.getAsObject()->empty() ? "{}" : "{ ... }");
283 // Prints a semi-expanded version of a value that is our main focus.
296 JOS.attributeBegin(KV->first);
297 abbreviate(KV->second, JOS);
325 const Segment &S = Path.back(); // Path is in reverse order.
330 if (!O || !O->get(FieldName))
334 JOS.attributeBegin(KV->first);
335 if (FieldName == StringRef(KV->first))
336 Recurse(KV->second, Path.drop_back(), Recurse);
338 abbreviate(KV->second, JOS);
345 if (!A || S.index() >= A->size())
362 // Simple recursive-descent JSON parser.
366 : Start(JSON.begin()), P(JSON.begin()), End(JSON.end()) {}
370 if (isUTF8(StringRef(Start, End - Start), &ErrOffset))
373 return parseError("Invalid UTF-8 sequence");
380 if (P == End)
382 return parseError("Text after end of document");
392 while (P != End && (*P == ' ' || *P == '\r' || *P == '\n' || *P == '\t'))
402 char next() { return P == End ? 0 : *P++; }
403 char peek() { return P == End ? 0 : *P; }
407 C == 'e' || C == 'E' || C == '+' || C == '-' || C == '.';
411 const char *Start, *P, *End;
417 if (P == End)
420 // Bare null/true/false are easy - first char identifies them.
451 if (!parseValue(A.back()))
505 // Read the number into a string. (Must be null-terminated for strto*).
510 char *End;
512 // We check for errno for out of bounds errors and for End == S.end()
515 int64_t I = std::strtoll(S.c_str(), &End, 10);
516 if (End == S.end() && errno != ERANGE) {
523 if (First != '-') {
525 uint64_t UI = std::strtoull(S.c_str(), &End, 10);
526 if (End == S.end() && errno != ERANGE) {
532 Out = std::strtod(S.c_str(), &End);
533 return End == S.end() || parseError("Invalid JSON value (number?)");
539 if (LLVM_UNLIKELY(P == End))
609 // Parse a UTF-16 \uNNNN escape sequence. "\u" has already been consumed.
615 auto Invalid = [&] { Out.append(/* UTF-8 */ {'\xef', '\xbf', '\xbd'}); };
617 auto Parse4Hex = [this](uint16_t &Out) -> bool {
624 Out |= (C > '9') ? (C & ~0x20) - 'A' + 10 : (C - '0');
628 uint16_t First; // UTF-16 code unit from the first \u escape.
632 // We loop to allow proper surrogate-pair error handling.
634 // Case 1: the UTF-16 code unit is already a codepoint in the BMP.
648 if (LLVM_UNLIKELY(P + 2 > End || *P != '\\' || *(P + 1) != 'u')) {
663 encodeUtf8(0x10000 | ((First - 0xD800) << 10) | (Second - 0xDC00), Out);
678 std::make_unique<ParseError>(Msg, Line, P - StartOfLine, P - Start));
694 // Fast-path for ASCII, which is valid UTF-8.
703 *ErrOffset = Rest - Data;
708 // This isn't particularly efficient, but is only for error-recovery.
714 Codepoints.resize(Out32 - Codepoints.data());
720 Res.resize(reinterpret_cast<char *>(Out8) - Res.data());
786 attribute(E->first, E->second);
792 assert(Stack.back().Ctx != Object && "Only attributes allowed here");
793 if (Stack.back().HasValue) {
794 assert(Stack.back().Ctx != Singleton && "Only one value allowed here");
797 if (Stack.back().Ctx == Array)
800 Stack.back().HasValue = true;
825 if (Stack.size() > 1 && Stack.back().Ctx == Singleton) {
843 Stack.back().Ctx = Array;
849 assert(Stack.back().Ctx == Array);
850 Indent -= IndentSize;
851 if (Stack.back().HasValue)
862 Stack.back().Ctx = Object;
868 assert(Stack.back().Ctx == Object);
869 Indent -= IndentSize;
870 if (Stack.back().HasValue)
879 assert(Stack.back().Ctx == Object);
880 if (Stack.back().HasValue)
884 Stack.back().HasValue = true;
886 Stack.back().Ctx = Singleton;
890 assert(false && "Invalid UTF-8 in attribute key");
899 assert(Stack.back().Ctx == Singleton);
900 assert(Stack.back().HasValue && "Attribute must have a value");
903 assert(Stack.back().Ctx == Object);
909 Stack.back().Ctx = RawValue;
914 assert(Stack.back().Ctx == RawValue);