@@ -35,6 +35,34 @@ namespace tao
3535 }
3636 }
3737
38+ inline std::string json_pointer_next_token ( const char * & p, const char * e )
39+ {
40+ std::string result;
41+ // TODO: Find next '/' first, call result.reserve( x )?
42+ while ( p != e ) {
43+ switch ( *p ) {
44+ case ' /' :
45+ return result;
46+ case ' ~' :
47+ switch ( *++p ) {
48+ case ' 0' :
49+ result += ' ~' ;
50+ break ;
51+ case ' 1' :
52+ result += ' /' ;
53+ break ;
54+ default :
55+ assert ( !" code should be unreachable" ); // LCOV_EXCL_LINE
56+ }
57+ ++p;
58+ break ;
59+ default :
60+ result += *p++;
61+ }
62+ }
63+ return result;
64+ }
65+
3866 } // internal
3967
4068 // RFC 6901
@@ -86,40 +114,17 @@ namespace tao
86114 std::pair< json_pointer, std::string > split () const
87115 {
88116 const auto p = m_value.rfind ( ' /' );
89- return { json_pointer ( m_value.substr ( 0 , p ) ), m_value.substr ( p + 1 ) };
117+ if ( p == std::string::npos ) {
118+ return { * this , " " };
119+ }
120+ const char * b = m_value.data () + p;
121+ const char * e = m_value.data () + m_value.size ();
122+ return { json_pointer ( m_value.substr ( 0 , p ) ), internal::json_pointer_next_token ( ++b, e ) };
90123 }
91124 };
92125
93126 namespace internal
94127 {
95- inline std::string json_pointer_next_token ( const char * & p, const char * e )
96- {
97- std::string result;
98- // TODO: Find next '/' first, call result.reserve( x )?
99- while ( p != e ) {
100- switch ( *p ) {
101- case ' /' :
102- return result;
103- case ' ~' :
104- switch ( *++p ) {
105- case ' 0' :
106- result += ' ~' ;
107- break ;
108- case ' 1' :
109- result += ' /' ;
110- break ;
111- default :
112- assert ( !" code should be unreachable" ); // LCOV_EXCL_LINE
113- }
114- ++p;
115- break ;
116- default :
117- result += *p++;
118- }
119- }
120- return result;
121- }
122-
123128 inline unsigned long long json_pointer_token_to_index ( const std::string & t )
124129 {
125130 if ( ( t.find_first_not_of ( " 0123456789" ) != std::string::npos ) || ( t.size () > 1 && t[ 0 ] == ' 0' ) ) {
@@ -131,7 +136,7 @@ namespace tao
131136 template < typename T >
132137 T & json_pointer_at ( T * v, const json_pointer & k )
133138 {
134- const char * p = k.value ().c_str ();
139+ const char * p = k.value ().data ();
135140 const char * e = p + k.value ().size ();
136141 while ( p != e ) {
137142 switch ( v->type () ) {
0 commit comments