@@ -17,6 +17,9 @@ extern "C" {
1717}
1818#include < mruby/cpp_helpers.hpp>
1919
20+ #include < string>
21+ #include < sstream>
22+
2023#if ((defined(__has_builtin) && __has_builtin(__builtin_expect))||(__GNUC__ >= 3) || (__INTEL_COMPILER >= 800) || defined(__clang__))
2124#define likely (x ) __builtin_expect(!!(x), 1 )
2225#define unlikely (x ) __builtin_expect(!!(x), 0 )
@@ -640,39 +643,20 @@ mrb_msgpack_unpack_lazy_m(mrb_state *mrb, mrb_value self)
640643 return mrb_undef_value ();
641644}
642645
643- #include < string>
644- #include < sstream>
645-
646646static std::string_view
647647unescape_json_pointer_sv (std::string_view s, std::string &scratch) {
648- // table maps '0' and '1' to unescaped chars, 0 means "no special mapping"
649- static constexpr unsigned char esc_table[256 ] = {
650- /* ... all zero-initialized ... */
651- [' 0' ] = ' ~' ,
652- [' 1' ] = ' /'
653- };
654-
655648 scratch.clear ();
656649 scratch.reserve (s.size ());
657-
658650 for (size_t i = 0 ; i < s.size (); ++i) {
659- unsigned char c = static_cast <unsigned char >(s[i]);
660- if (c == ' ~' && i + 1 < s.size ()) {
661- unsigned char next = static_cast <unsigned char >(s[i + 1 ]);
662- unsigned char mapped = esc_table[next];
663- if (mapped) {
664- scratch.push_back (static_cast <char >(mapped));
665- ++i; // skip next
666- continue ;
667- }
651+ if (s[i] == ' ~' && i + 1 < s.size ()) {
652+ if (s[i + 1 ] == ' 0' ) { scratch.push_back (' ~' ); ++i; continue ; }
653+ if (s[i + 1 ] == ' 1' ) { scratch.push_back (' /' ); ++i; continue ; }
668654 }
669- scratch.push_back (static_cast < char >(c) );
655+ scratch.push_back (s[i] );
670656 }
671-
672657 return std::string_view (scratch);
673658}
674659
675-
676660static mrb_value
677661mrb_msgpack_object_handle_at_pointer (mrb_state *mrb, mrb_value self)
678662{
@@ -688,6 +672,15 @@ mrb_msgpack_object_handle_at_pointer(mrb_state *mrb, mrb_value self)
688672
689673 const msgpack::object *current = &handle->oh .get ();
690674
675+ if (pointer.empty () || pointer == " /" ) {
676+ return mrb_unpack_msgpack_obj (
677+ mrb,
678+ mrb_iv_get (mrb, self, MRB_SYM (data)),
679+ *current,
680+ handle->referenced
681+ );
682+ }
683+
691684 if (pointer.front () != ' /' ) {
692685 mrb_raise (mrb, E_ARGUMENT_ERROR, " JSON Pointer must start with '/'" );
693686 return mrb_undef_value ();
0 commit comments