@@ -602,6 +602,16 @@ JsonParseResult emitNumberFromRawToken(std::string_view input, JsonEventSink *si
602602 return emitSink (sink, sink->on_number (raw_number), " handling a number" );
603603}
604604
605+ JsonParseResult decodeStringEventValue (const jsoncons::staj_event &event,
606+ const jsoncons::ser_context &context, jsoncons::string_view *decoded) {
607+ std::error_code error;
608+ *decoded = event.get <jsoncons::string_view>(error);
609+ if (error) {
610+ return fromJsonconsError (error, context);
611+ }
612+ return makeResult (JsonParseStatus::Ok);
613+ }
614+
605615JsonParseResult emitEvent (std::string_view input, JsonEventSink *sink,
606616 RawJsonTokenCursor *token_cursor, const jsoncons::staj_event &event,
607617 const jsoncons::ser_context &context) {
@@ -617,17 +627,19 @@ JsonParseResult emitEvent(std::string_view input, JsonEventSink *sink,
617627 case jsoncons::staj_event_type::end_array:
618628 return emitSink (sink, sink->on_end_array (), " ending an array" );
619629 case jsoncons::staj_event_type::key: {
620- jsoncons::string_view decoded = event.get <jsoncons::string_view>(error);
621- if (error) {
622- return fromJsonconsError (error, context);
630+ jsoncons::string_view decoded;
631+ if (JsonParseResult result = decodeStringEventValue (event, context,
632+ &decoded); !result.ok ()) {
633+ return result;
623634 }
624635 return emitSink (sink, sink->on_key (std::string_view (decoded.data (),
625636 decoded.size ())), " processing an object key" );
626637 }
627638 case jsoncons::staj_event_type::string_value: {
628- jsoncons::string_view decoded = event.get <jsoncons::string_view>(error);
629- if (error) {
630- return fromJsonconsError (error, context);
639+ jsoncons::string_view decoded;
640+ if (JsonParseResult result = decodeStringEventValue (event, context,
641+ &decoded); !result.ok ()) {
642+ return result;
631643 }
632644 if (isNumericStringEvent (event)) {
633645 std::string sync_detail;
@@ -713,6 +725,11 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
713725 std::chrono::duration_cast<std::chrono::nanoseconds>(
714726 std::chrono::steady_clock::now () - event_loop_start).count ()));
715727 };
728+ const auto finish_with_event_loop = [&record_event_loop](
729+ JsonParseResult result) {
730+ record_event_loop ();
731+ return result;
732+ };
716733#else
717734 RawJsonTokenCursor token_cursor (input);
718735#endif
@@ -721,15 +738,16 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
721738 if (JsonParseResult result = emitEvent (input, sink, &token_cursor,
722739 cursor.current (), cursor.context ()); !result.ok ()) {
723740#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
724- record_event_loop ( );
741+ return finish_with_event_loop (result );
725742#endif
726743 return result;
727744 }
728745
729746 cursor.next (error);
730747 if (error) {
731748#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
732- record_event_loop ();
749+ return finish_with_event_loop (
750+ fromJsonconsError (error, cursor.context ()));
733751#endif
734752 return fromJsonconsError (error, cursor.context ());
735753 }
@@ -738,7 +756,8 @@ JsonParseResult parseDocumentWithJsoncons(const std::string &input,
738756 cursor.check_done (error);
739757 if (error) {
740758#ifdef MSC_JSON_AUDIT_INSTRUMENTATION
741- record_event_loop ();
759+ return finish_with_event_loop (fromJsonconsError (error,
760+ cursor.context ()));
742761#endif
743762 return fromJsonconsError (error, cursor.context ());
744763 }
0 commit comments