bool handle_surrogate_pair()

in src/codec/string.cpp [97:115]


bool handle_surrogate_pair(decode_context &context, std::string &out, unsigned p) {
  if (json_unlikely(is_high_surrogate(p))) {
    // Parse low surrogate
    if (detail::peek_2(context, '\\', 'u')) {
      detail::skip_unchecked_n(context, 2);
      const auto n = decode_hex_number(context);
      if (json_likely(is_low_surrogate(n))) {
        // Any Unicode codepoint encoded by a surrogate pair is 4 bytes in UTF-8
        encode_utf8_4(out, codepoint_from_surrogate_pair(p, n));
        return true;
      } else {
        // Rewind context to before the escape sequence
        context.position -= 6;
      }
    }
  }

  return false;
}