4#include "Stroika/Frameworks/StroikaPreComp.h"
6#include "Stroika/Foundation/Characters/String2Int.h"
7#include "Stroika/Foundation/DataExchange/BadFormatException.h"
25String JSON::PointerType::Context::MapElt::ToString ()
const
29 sb <<
"orig: " << fOrigValue;
30 sb <<
", eltName: " << fEltName;
40String JSON::PointerType::Context::SeqElt::ToString ()
const
44 sb <<
"orig: " << fOrigValue;
45 sb <<
", index: " << this->fIndex;
56 using MapElt = JSON::PointerType::Context::MapElt;
57 using SeqElt = JSON::PointerType::Context::SeqElt;
58 auto PopOneAtAtATPopOneAtAtATime_ (
Stack<variant<MapElt, SeqElt>> stack,
const optional<VariantValue>& leafToUse) -> optional<VariantValue>
63 variant<MapElt, SeqElt> cur = stack.Pop ();
64 if (
auto om = get_if<MapElt> (&cur)) {
67 r.
Add (om->fEltName, leafToUse);
69 return PopOneAtAtATPopOneAtAtATime_ (stack,
VariantValue{r});
71 else if (
auto os = get_if<SeqElt> (&cur)) {
73 if (os->fIndex > r.
size ()) {
75 Execution::Throw (kExcept_);
78 r.
SetAt (os->fIndex, *leafToUse);
80 return PopOneAtAtATPopOneAtAtATime_ (stack,
VariantValue{r});
91 return PopOneAtAtATPopOneAtAtATime_ (fStack, leafToUse);
94String JSON::PointerType::Context::ToString ()
const
98 sb <<
"stack: " << fStack;
110 PointerType::PointerType (
const String& s)
112 optional<Character> prevChar;
113 bool startedSection =
false;
116 auto maybeHandleCharAfterTwiddle = [&] (
Character c) ->
bool {
117 if (prevChar ==
'~') {
118 switch (c.GetCharacterCode ()) {
127 Execution::Throw (kExcept_);
136 if (maybeHandleCharAfterTwiddle (c)) {
140 if (startedSection) {
141 fComponents_.Append (curSectionSB);
142 curSectionSB.clear ();
144 startedSection =
true;
146 else if (startedSection) {
153 Execution::Throw (kExcept_);
157 if (prevChar ==
'/' or not curSectionSB.
empty ()) {
158 fComponents_.Append (curSectionSB);
166 for (
String component : this->fComponents_) {
167 switch (curNode.GetType ()) {
168 case VariantValue::eArray: {
170 size_t i = component ==
"-"sv ? sv.
size () : Characters::String2Int<size_t> (component);
171 if (i > sv.
size ()) {
175 if (contextOut !=
nullptr) {
176 contextOut->fStack.Push (Context::SeqElt{.fOrigValue = sv, .fIndex = i});
179 case VariantValue::eMap: {
181 if (
auto o = mv.
Lookup (component)) {
187 if (contextOut !=
nullptr) {
188 contextOut->fStack.Push (Context::MapElt{.fOrigValue = mv, .fEltName = component});
200String JSON::PointerType::ToString ()
const
#define AssertNotReached()
Similar to String, but intended to more efficiently construct a String. Mutable type (String is large...
nonvirtual bool empty() const noexcept
String is like std::u32string, except it is much easier to use, often much more space efficient,...
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
nonvirtual optional< mapped_type > Lookup(ArgByValueType< key_type > key) const
A generalization of a vector: a container whose elements are keyed by the natural numbers.
nonvirtual void SetAt(size_t i, ArgByValueType< value_type > item)
nonvirtual optional< tuple< Context, VariantValue > > ApplyWithContext(const VariantValue &v) const
Simple variant-value (case variant union) object, with (variant) basic types analogous to a value in ...
nonvirtual RETURNTYPE As() const
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument function (or lambda) on each element of the container.
nonvirtual size_t size() const
Returns the number of items contained.
String ToString(T &&t, ARGS... args)
Return a debug-friendly, display version of the argument: not guaranteed parsable or usable except fo...
optional< VariantValue > ConstructNewFrom(const optional< VariantValue > &leafToUse) const