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