MCPcopy Create free account
hub / github.com/boostorg/json / parse_escaped

Method parse_escaped

include/boost/json/basic_parser_impl.hpp:1124–1688  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1122template<class Handler>
1123template<bool StackEmpty_>
1124const char*
1125basic_parser<Handler>::
1126parse_escaped(
1127 const char* p,
1128 std::size_t& total,
1129 std::integral_constant<bool, StackEmpty_> stack_empty,
1130 bool is_key,
1131 bool allow_bad_utf16)
1132{
1133 constexpr unsigned urc = 0xFFFD; // Unicode replacement character
1134 auto const ev_too_large = is_key?
1135 error::key_too_large : error::string_too_large;
1136 auto const max_size = is_key?
1137 Handler::max_key_size : Handler::max_string_size;
1138 int digit;
1139
1140 //---------------------------------------------------------------
1141 //
1142 // To handle escapes, a local temporary buffer accumulates
1143 // the unescaped result. The algorithm attempts to fill the
1144 // buffer to capacity before invoking the handler.
1145 // In some cases the temporary buffer needs to be flushed
1146 // before it is full:
1147 // * When the closing double quote is seen
1148 // * When there in no more input (and more is expected later)
1149 // A goal of the algorithm is to call the handler as few times
1150 // as possible. Thus, when the first escape is encountered,
1151 // the algorithm attempts to fill the temporary buffer first.
1152 //
1153 detail::buffer<BOOST_JSON_STACK_BUFFER_SIZE> temp;
1154
1155 // Unescaped JSON is never larger than its escaped version.
1156 // To efficiently process only what will fit in the temporary buffer,
1157 // the size of the input stream is temporarily "clipped" to the size
1158 // of the temporary buffer.
1159 // handle escaped character
1160 detail::clipped_const_stream cs(p, end_);
1161 cs.clip(temp.max_size());
1162
1163 if(! stack_empty && ! st_.empty())
1164 {
1165 state st;
1166 st_.pop(st);
1167 switch(st)
1168 {
1169 default: BOOST_JSON_UNREACHABLE();
1170 case state::str3: goto do_str3;
1171 case state::str4: goto do_str4;
1172 case state::str5: goto do_str5;
1173 case state::str6: goto do_str6;
1174 case state::str7: goto do_str7;
1175 case state::sur1: goto do_sur1;
1176 case state::sur2: goto do_sur2;
1177 case state::sur3: goto do_sur3;
1178 case state::sur4: goto do_sur4;
1179 case state::sur5: goto do_sur5;
1180 case state::sur6: goto do_sur6;
1181 }

Callers

nothing calls this directly

Calls 15

hex_digitFunction · 0.85
popMethod · 0.80
append_utf8Method · 0.80
clipMethod · 0.45
max_sizeMethod · 0.45
emptyMethod · 0.45
capacityMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
on_key_partMethod · 0.45
getMethod · 0.45
on_string_partMethod · 0.45

Tested by

no test coverage detected