Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
21a44da8
Commit
21a44da8
authored
Jan 24, 2016
by
Niels
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #189 from twelsby/issue171
Fixed Issue #171 - added two extra template overloads of operator[] for T* arguments
parents
f8544105
bd0f3001
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
527 additions
and
750 deletions
+527
-750
json.hpp
src/json.hpp
+405
-742
json.hpp.re2c
src/json.hpp.re2c
+74
-8
unit.cpp
test/unit.cpp
+48
-0
No files found.
src/json.hpp
View file @
21a44da8
...
...
@@ -2675,7 +2675,9 @@ class basic_json
std
::
enable_if
<
not
std
::
is_pointer
<
ValueType
>::
value
and
not
std
::
is_same
<
ValueType
,
typename
string_t
::
value_type
>::
value
#ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
and
not
std
::
is_same
<
ValueType
,
std
::
initializer_list
<
typename
string_t
::
value_type
>>::
value
#endif
,
int
>::
type
=
0
>
operator
ValueType
()
const
{
...
...
@@ -3060,8 +3062,6 @@ class basic_json
the object and filled with a `null` value to make `key` a valid reference.
In case the value was `null` before, it is converted to an object.
@note This function is required for compatibility reasons with Clang.
@param[in] key key of the element to access
@return reference to the element at key @a key
...
...
@@ -3081,7 +3081,75 @@ class basic_json
@since version 1.0.0
*/
template
<
typename
T
,
std
::
size_t
n
>
reference
operator
[](
const
T
(
&
key
)[
n
])
reference
operator
[](
T
*
(
&
key
)[
n
])
{
return
operator
[](
static_cast
<
const
T
>
(
key
));
}
/*!
@brief read-only access specified object element
Returns a const reference to the element at with specified key @a key. No
bounds checking is performed.
@warning If the element with key @a key does not exist, the behavior is
undefined.
@note This function is required for compatibility reasons with Clang.
@param[in] key key of the element to access
@return const reference to the element at key @a key
@throw std::domain_error if JSON is not an object; example: `"cannot use
operator[] with null"`
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be read using
the [] operator.,operatorarray__key_type_const}
@sa @ref at(const typename object_t::key_type&) for access by reference
with range checking
@sa @ref value() for access by value with a default value
@since version 1.0.0
*/
template
<
typename
T
,
std
::
size_t
n
>
const_reference
operator
[](
T
*
(
&
key
)[
n
])
const
{
return
operator
[](
static_cast
<
const
T
>
(
key
));
}
/*!
@brief access specified object element
Returns a reference to the element at with specified key @a key.
@note If @a key is not found in the object, then it is silently added to
the object and filled with a `null` value to make `key` a valid reference.
In case the value was `null` before, it is converted to an object.
@param[in] key key of the element to access
@return reference to the element at key @a key
@throw std::domain_error if JSON is not an object or null; example:
`"cannot use operator[] with null"`
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be read and
written using the [] operator.,operatorarray__key_type}
@sa @ref at(const typename object_t::key_type&) for access by reference
with range checking
@sa @ref value() for access by value with a default value
@since version 1.0.1
*/
template
<
typename
T
>
reference
operator
[](
T
*
key
)
{
// implicitly convert null to object
if
(
is_null
())
...
...
@@ -3111,8 +3179,6 @@ class basic_json
@warning If the element with key @a key does not exist, the behavior is
undefined.
@note This function is required for compatibility reasons with Clang.
@param[in] key key of the element to access
@return const reference to the element at key @a key
...
...
@@ -3129,10 +3195,10 @@ class basic_json
with range checking
@sa @ref value() for access by value with a default value
@since version 1.0.
0
@since version 1.0.
1
*/
template
<
typename
T
,
std
::
size_t
n
>
const_reference
operator
[](
const
T
(
&
key
)[
n
]
)
const
template
<
typename
T
>
const_reference
operator
[](
T
*
key
)
const
{
// at only works for objects
if
(
is_object
())
...
...
@@ -6745,789 +6811,386 @@ class basic_json
m_start
=
m_cursor
;
assert
(
m_start
!=
nullptr
);
{
lexer_char_t
yych
;
unsigned
int
yyaccept
=
0
;
static
const
unsigned
char
yybm
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
32
,
32
,
0
,
0
,
32
,
0
,
0
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
96
,
64
,
0
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
0
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
};
if
((
m_limit
-
m_cursor
)
<
5
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
':'
)
{
if
(
yych
<=
' '
)
{
if
(
yych
<=
'\n'
)
{
if
(
yych
<=
0x00
)
{
goto
basic_json_parser_28
;
}
if
(
yych
<=
0x08
)
{
goto
basic_json_parser_30
;
}
if
(
yych
>=
'\n'
)
{
goto
basic_json_parser_4
;
}
}
else
{
if
(
yych
==
'\r'
)
{
goto
basic_json_parser_2
;
}
if
(
yych
<=
0x1F
)
{
goto
basic_json_parser_30
;
}
}
}
else
{
if
(
yych
<=
','
)
{
if
(
yych
==
'"'
)
{
goto
basic_json_parser_27
;
}
if
(
yych
<=
'+'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_16
;
}
else
{
if
(
yych
<=
'/'
)
{
if
(
yych
<=
'-'
)
{
goto
basic_json_parser_23
;
}
goto
basic_json_parser_30
;
}
else
{
if
(
yych
<=
'0'
)
{
goto
basic_json_parser_24
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_26
;
}
goto
basic_json_parser_18
;
}
}
{
lexer_char_t
yych
;
unsigned
int
yyaccept
=
0
;
static
const
unsigned
char
yybm
[]
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
32
,
32
,
0
,
0
,
32
,
0
,
0
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
96
,
64
,
0
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
192
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
0
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
64
,
};
if
((
m_limit
-
m_cursor
)
<
5
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
':'
)
{
if
(
yych
<=
' '
)
{
if
(
yych
<=
'\n'
)
{
if
(
yych
<=
0x00
)
goto
basic_json_parser_28
;
if
(
yych
<=
0x08
)
goto
basic_json_parser_30
;
if
(
yych
>=
'\n'
)
goto
basic_json_parser_4
;
}
else
{
if
(
yych
==
'\r'
)
goto
basic_json_parser_2
;
if
(
yych
<=
0x1F
)
goto
basic_json_parser_30
;
}
}
else
{
if
(
yych
<=
','
)
{
if
(
yych
==
'"'
)
goto
basic_json_parser_27
;
if
(
yych
<=
'+'
)
goto
basic_json_parser_30
;
goto
basic_json_parser_16
;
}
else
{
if
(
yych
<=
'/'
)
{
if
(
yych
<=
'-'
)
goto
basic_json_parser_23
;
goto
basic_json_parser_30
;
}
else
{
if
(
yych
<=
'0'
)
goto
basic_json_parser_24
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_26
;
goto
basic_json_parser_18
;
}
}
else
{
if
(
yych
<=
'n'
)
{
if
(
yych
<=
']'
)
{
if
(
yych
==
'['
)
{
goto
basic_json_parser_8
;
}
if
(
yych
<=
'\\'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_10
;
}
else
{
if
(
yych
==
'f'
)
{
goto
basic_json_parser_22
;
}
if
(
yych
<=
'm'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_20
;
}
}
else
{
if
(
yych
<=
'{'
)
{
if
(
yych
==
't'
)
{
goto
basic_json_parser_21
;
}
if
(
yych
<=
'z'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_12
;
}
else
{
if
(
yych
<=
'}'
)
{
if
(
yych
<=
'|'
)
{
goto
basic_json_parser_30
;
}
goto
basic_json_parser_14
;
}
else
{
if
(
yych
==
0xEF
)
{
goto
basic_json_parser_6
;
}
goto
basic_json_parser_30
;
}
}
}
}
else
{
if
(
yych
<=
'n'
)
{
if
(
yych
<=
']'
)
{
if
(
yych
==
'['
)
goto
basic_json_parser_8
;
if
(
yych
<=
'\\'
)
goto
basic_json_parser_30
;
goto
basic_json_parser_10
;
}
else
{
if
(
yych
==
'f'
)
goto
basic_json_parser_22
;
if
(
yych
<=
'm'
)
goto
basic_json_parser_30
;
goto
basic_json_parser_20
;
}
}
else
{
if
(
yych
<=
'{'
)
{
if
(
yych
==
't'
)
goto
basic_json_parser_21
;
if
(
yych
<=
'z'
)
goto
basic_json_parser_30
;
goto
basic_json_parser_12
;
}
else
{
if
(
yych
<=
'}'
)
{
if
(
yych
<=
'|'
)
goto
basic_json_parser_30
;
goto
basic_json_parser_14
;
}
else
{
if
(
yych
==
0xEF
)
goto
basic_json_parser_6
;
goto
basic_json_parser_30
;
}
}
}
}
basic_json_parser_2
:
++
m_cursor
;
yych
=
*
m_cursor
;
goto
basic_json_parser_5
;
++
m_cursor
;
yych
=
*
m_cursor
;
goto
basic_json_parser_5
;
basic_json_parser_3
:
{
return
scan
();
}
{
return
scan
();
}
basic_json_parser_4
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
basic_json_parser_5
:
if
(
yybm
[
0
+
yych
]
&
32
)
{
goto
basic_json_parser_4
;
}
goto
basic_json_parser_3
;
if
(
yybm
[
0
+
yych
]
&
32
)
{
goto
basic_json_parser_4
;
}
goto
basic_json_parser_3
;
basic_json_parser_6
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
0xBB
)
{
goto
basic_json_parser_64
;
}
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
0xBB
)
goto
basic_json_parser_64
;
basic_json_parser_7
:
{
return
token_type
::
parse_error
;
}
{
return
token_type
::
parse_error
;
}
basic_json_parser_8
:
++
m_cursor
;
{
return
token_type
::
begin_array
;
}
++
m_cursor
;
{
return
token_type
::
begin_array
;
}
basic_json_parser_10
:
++
m_cursor
;
{
return
token_type
::
end_array
;
}
++
m_cursor
;
{
return
token_type
::
end_array
;
}
basic_json_parser_12
:
++
m_cursor
;
{
return
token_type
::
begin_object
;
}
++
m_cursor
;
{
return
token_type
::
begin_object
;
}
basic_json_parser_14
:
++
m_cursor
;
{
return
token_type
::
end_object
;
}
++
m_cursor
;
{
return
token_type
::
end_object
;
}
basic_json_parser_16
:
++
m_cursor
;
{
return
token_type
::
value_separator
;
}
++
m_cursor
;
{
return
token_type
::
value_separator
;
}
basic_json_parser_18
:
++
m_cursor
;
{
return
token_type
::
name_separator
;
}
++
m_cursor
;
{
return
token_type
::
name_separator
;
}
basic_json_parser_20
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'u'
)
{
goto
basic_json_parser_60
;
}
goto
basic_json_parser_7
;
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'u'
)
goto
basic_json_parser_60
;
goto
basic_json_parser_7
;
basic_json_parser_21
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'r'
)
{
goto
basic_json_parser_56
;
}
goto
basic_json_parser_7
;
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'r'
)
goto
basic_json_parser_56
;
goto
basic_json_parser_7
;
basic_json_parser_22
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'a'
)
{
goto
basic_json_parser_51
;
}
goto
basic_json_parser_7
;
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
==
'a'
)
goto
basic_json_parser_51
;
goto
basic_json_parser_7
;
basic_json_parser_23
:
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_7
;
}
if
(
yych
<=
'0'
)
{
goto
basic_json_parser_50
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_41
;
}
goto
basic_json_parser_7
;
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_7
;
if
(
yych
<=
'0'
)
goto
basic_json_parser_50
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_41
;
goto
basic_json_parser_7
;
basic_json_parser_24
:
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
{
goto
basic_json_parser_43
;
}
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
}
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
goto
basic_json_parser_43
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
}
basic_json_parser_25
:
{
return
token_type
::
value_number
;
}
{
return
token_type
::
value_number
;
}
basic_json_parser_26
:
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
goto
basic_json_parser_42
;
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
goto
basic_json_parser_42
;
basic_json_parser_27
:
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
0x0F
)
{
goto
basic_json_parser_7
;
}
goto
basic_json_parser_32
;
yyaccept
=
0
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
0x0F
)
goto
basic_json_parser_7
;
goto
basic_json_parser_32
;
basic_json_parser_28
:
++
m_cursor
;
{
return
token_type
::
end_of_input
;
}
++
m_cursor
;
{
return
token_type
::
end_of_input
;
}
basic_json_parser_30
:
yych
=
*++
m_cursor
;
goto
basic_json_parser_7
;
yych
=
*++
m_cursor
;
goto
basic_json_parser_7
;
basic_json_parser_31
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
basic_json_parser_32
:
if
(
yybm
[
0
+
yych
]
&
64
)
{
goto
basic_json_parser_31
;
}
if
(
yych
<=
0x0F
)
{
goto
basic_json_parser_33
;
}
if
(
yych
<=
'"'
)
{
goto
basic_json_parser_35
;
}
goto
basic_json_parser_34
;
if
(
yybm
[
0
+
yych
]
&
64
)
{
goto
basic_json_parser_31
;
}
if
(
yych
<=
0x0F
)
goto
basic_json_parser_33
;
if
(
yych
<=
'"'
)
goto
basic_json_parser_35
;
goto
basic_json_parser_34
;
basic_json_parser_33
:
m_cursor
=
m_marker
;
if
(
yyaccept
==
0
)
{
goto
basic_json_parser_7
;
}
else
{
goto
basic_json_parser_25
;
}
m_cursor
=
m_marker
;
if
(
yyaccept
==
0
)
{
goto
basic_json_parser_7
;
}
else
{
goto
basic_json_parser_25
;
}
basic_json_parser_34
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'e'
)
{
if
(
yych
<=
'/'
)
{
if
(
yych
==
'"'
)
{
goto
basic_json_parser_31
;
}
if
(
yych
<=
'.'
)
{
goto
basic_json_parser_33
;
}
goto
basic_json_parser_31
;
}
else
{
if
(
yych
<=
'\\'
)
{
if
(
yych
<=
'['
)
{
goto
basic_json_parser_33
;
}
goto
basic_json_parser_31
;
}
else
{
if
(
yych
==
'b'
)
{
goto
basic_json_parser_31
;
}
goto
basic_json_parser_33
;
}
}
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'e'
)
{
if
(
yych
<=
'/'
)
{
if
(
yych
==
'"'
)
goto
basic_json_parser_31
;
if
(
yych
<=
'.'
)
goto
basic_json_parser_33
;
goto
basic_json_parser_31
;
}
else
{
if
(
yych
<=
'\\'
)
{
if
(
yych
<=
'['
)
goto
basic_json_parser_33
;
goto
basic_json_parser_31
;
}
else
{
if
(
yych
==
'b'
)
goto
basic_json_parser_31
;
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'q'
)
{
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_31
;
}
if
(
yych
==
'n'
)
{
goto
basic_json_parser_31
;
}
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
's'
)
{
if
(
yych
<=
'r'
)
{
goto
basic_json_parser_31
;
}
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
't'
)
{
goto
basic_json_parser_31
;
}
if
(
yych
<=
'u'
)
{
goto
basic_json_parser_37
;
}
goto
basic_json_parser_33
;
}
}
}
}
else
{
if
(
yych
<=
'q'
)
{
if
(
yych
<=
'f'
)
goto
basic_json_parser_31
;
if
(
yych
==
'n'
)
goto
basic_json_parser_31
;
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
's'
)
{
if
(
yych
<=
'r'
)
goto
basic_json_parser_31
;
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
't'
)
goto
basic_json_parser_31
;
if
(
yych
<=
'u'
)
goto
basic_json_parser_37
;
goto
basic_json_parser_33
;
}
}
}
basic_json_parser_35
:
++
m_cursor
;
{
return
token_type
::
value_string
;
}
++
m_cursor
;
{
return
token_type
::
value_string
;
}
basic_json_parser_37
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
':'
)
{
goto
basic_json_parser_33
;
}
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_38
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
'g'
)
{
goto
basic_json_parser_33
;
}
}
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
>=
':'
)
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_38
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_33
;
if
(
yych
>=
'g'
)
goto
basic_json_parser_33
;
}
basic_json_parser_38
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
':'
)
{
goto
basic_json_parser_33
;
}
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_39
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
'g'
)
{
goto
basic_json_parser_33
;
}
}
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
>=
':'
)
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_39
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_33
;
if
(
yych
>=
'g'
)
goto
basic_json_parser_33
;
}
basic_json_parser_39
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
':'
)
{
goto
basic_json_parser_33
;
}
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_40
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
'g'
)
{
goto
basic_json_parser_33
;
}
}
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
>=
':'
)
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_40
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_33
;
if
(
yych
>=
'g'
)
goto
basic_json_parser_33
;
}
basic_json_parser_40
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_31
;
}
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'F'
)
{
goto
basic_json_parser_31
;
}
if
(
yych
<=
'`'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
<=
'f'
)
{
goto
basic_json_parser_31
;
}
goto
basic_json_parser_33
;
}
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'@'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_31
;
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'F'
)
goto
basic_json_parser_31
;
if
(
yych
<=
'`'
)
goto
basic_json_parser_33
;
if
(
yych
<=
'f'
)
goto
basic_json_parser_31
;
goto
basic_json_parser_33
;
}
basic_json_parser_41
:
yyaccept
=
1
;
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
yyaccept
=
1
;
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
basic_json_parser_42
:
if
(
yybm
[
0
+
yych
]
&
128
)
{
goto
basic_json_parser_41
;
}
if
(
yych
<=
'D'
)
{
if
(
yych
!=
'.'
)
{
goto
basic_json_parser_25
;
}
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
goto
basic_json_parser_25
;
}
if
(
yybm
[
0
+
yych
]
&
128
)
{
goto
basic_json_parser_41
;
}
if
(
yych
<=
'D'
)
{
if
(
yych
!=
'.'
)
goto
basic_json_parser_25
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
goto
basic_json_parser_25
;
}
basic_json_parser_43
:
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_48
;
}
goto
basic_json_parser_33
;
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_48
;
goto
basic_json_parser_33
;
basic_json_parser_44
:
yych
=
*++
m_cursor
;
if
(
yych
<=
','
)
{
if
(
yych
!=
'+'
)
{
goto
basic_json_parser_33
;
}
}
else
{
if
(
yych
<=
'-'
)
{
goto
basic_json_parser_45
;
}
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_46
;
}
goto
basic_json_parser_33
;
}
yych
=
*++
m_cursor
;
if
(
yych
<=
','
)
{
if
(
yych
!=
'+'
)
goto
basic_json_parser_33
;
}
else
{
if
(
yych
<=
'-'
)
goto
basic_json_parser_45
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_46
;
goto
basic_json_parser_33
;
}
basic_json_parser_45
:
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_33
;
}
if
(
yych
>=
':'
)
{
goto
basic_json_parser_33
;
}
yych
=
*++
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_33
;
if
(
yych
>=
':'
)
goto
basic_json_parser_33
;
basic_json_parser_46
:
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_25
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_46
;
}
goto
basic_json_parser_25
;
++
m_cursor
;
if
(
m_limit
<=
m_cursor
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'/'
)
goto
basic_json_parser_25
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_46
;
goto
basic_json_parser_25
;
basic_json_parser_48
:
yyaccept
=
1
;
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
{
yyfill
();
// LCOV_EXCL_LINE;
}
yych
=
*
m_cursor
;
if
(
yych
<=
'D'
)
{
if
(
yych
<=
'/'
)
{
goto
basic_json_parser_25
;
}
if
(
yych
<=
'9'
)
{
goto
basic_json_parser_48
;
}
goto
basic_json_parser_25
;
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
goto
basic_json_parser_25
;
}
yyaccept
=
1
;
m_marker
=
++
m_cursor
;
if
((
m_limit
-
m_cursor
)
<
3
)
yyfill
();
// LCOV_EXCL_LINE;
yych
=
*
m_cursor
;
if
(
yych
<=
'D'
)
{
if
(
yych
<=
'/'
)
goto
basic_json_parser_25
;
if
(
yych
<=
'9'
)
goto
basic_json_parser_48
;
goto
basic_json_parser_25
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
goto
basic_json_parser_25
;
}
basic_json_parser_50
:
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
{
goto
basic_json_parser_43
;
}
goto
basic_json_parser_25
;
}
else
{
if
(
yych
<=
'E'
)
{
goto
basic_json_parser_44
;
}
if
(
yych
==
'e'
)
{
goto
basic_json_parser_44
;
}
goto
basic_json_parser_25
;
}
yyaccept
=
1
;
yych
=
*
(
m_marker
=
++
m_cursor
);
if
(
yych
<=
'D'
)
{
if
(
yych
==
'.'
)
goto
basic_json_parser_43
;
goto
basic_json_parser_25
;
}
else
{
if
(
yych
<=
'E'
)
goto
basic_json_parser_44
;
if
(
yych
==
'e'
)
goto
basic_json_parser_44
;
goto
basic_json_parser_25
;
}
basic_json_parser_51
:
yych
=
*++
m_cursor
;
if
(
yych
!=
'l'
)
{
goto
basic_json_parser_33
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
's'
)
{
goto
basic_json_parser_33
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
'e'
)
{
goto
basic_json_parser_33
;
}
++
m_cursor
;
{
return
token_type
::
literal_false
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
'l'
)
goto
basic_json_parser_33
;
yych
=
*++
m_cursor
;
if
(
yych
!=
's'
)
goto
basic_json_parser_33
;
yych
=
*++
m_cursor
;
if
(
yych
!=
'e'
)
goto
basic_json_parser_33
;
++
m_cursor
;
{
return
token_type
::
literal_false
;
}
basic_json_parser_56
:
yych
=
*++
m_cursor
;
if
(
yych
!=
'u'
)
{
goto
basic_json_parser_33
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
'e'
)
{
goto
basic_json_parser_33
;
}
++
m_cursor
;
{
return
token_type
::
literal_true
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
'u'
)
goto
basic_json_parser_33
;
yych
=
*++
m_cursor
;
if
(
yych
!=
'e'
)
goto
basic_json_parser_33
;
++
m_cursor
;
{
return
token_type
::
literal_true
;
}
basic_json_parser_60
:
yych
=
*++
m_cursor
;
if
(
yych
!=
'l'
)
{
goto
basic_json_parser_33
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
'l'
)
{
goto
basic_json_parser_33
;
}
++
m_cursor
;
{
return
token_type
::
literal_null
;
}
yych
=
*++
m_cursor
;
if
(
yych
!=
'l'
)
goto
basic_json_parser_33
;
yych
=
*++
m_cursor
;
if
(
yych
!=
'l'
)
goto
basic_json_parser_33
;
++
m_cursor
;
{
return
token_type
::
literal_null
;
}
basic_json_parser_64
:
yych
=
*++
m_cursor
;
if
(
yych
!=
0xBF
)
{
goto
basic_json_parser_33
;
}
++
m_cursor
;
{
return
scan
();
}
}
yych
=
*++
m_cursor
;
if
(
yych
!=
0xBF
)
goto
basic_json_parser_33
;
++
m_cursor
;
{
return
scan
();
}
}
}
...
...
src/json.hpp.re2c
View file @
21a44da8
...
...
@@ -2675,7 +2675,9 @@ class basic_json
std::enable_if<
not std::is_pointer<ValueType>::value
and not std::is_same<ValueType, typename string_t::value_type>::value
#ifndef _MSC_VER // Fix for issue #167 operator<< abiguity under VS2015
and not std::is_same<ValueType, std::initializer_list<typename string_t::value_type>>::value
#endif
, int>::type = 0>
operator ValueType() const
{
...
...
@@ -3060,8 +3062,6 @@ class basic_json
the object and filled with a `null` value to make `key` a valid reference.
In case the value was `null` before, it is converted to an object.
@note This function is required for compatibility reasons with Clang.
@param[in] key key of the element to access
@return reference to the element at key @a key
...
...
@@ -3081,7 +3081,75 @@ class basic_json
@since version 1.0.0
*/
template<typename T, std::size_t n>
reference operator[](const T (&key)[n])
reference operator[](T* (&key)[n])
{
return operator[](static_cast<const T>(key));
}
/*!
@brief read-only access specified object element
Returns a const reference to the element at with specified key @a key. No
bounds checking is performed.
@warning If the element with key @a key does not exist, the behavior is
undefined.
@note This function is required for compatibility reasons with Clang.
@param[in] key key of the element to access
@return const reference to the element at key @a key
@throw std::domain_error if JSON is not an object; example: `"cannot use
operator[] with null"`
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be read using
the [] operator.,operatorarray__key_type_const}
@sa @ref at(const typename object_t::key_type&) for access by reference
with range checking
@sa @ref value() for access by value with a default value
@since version 1.0.0
*/
template<typename T, std::size_t n>
const_reference operator[](T* (&key)[n]) const
{
return operator[](static_cast<const T>(key));
}
/*!
@brief access specified object element
Returns a reference to the element at with specified key @a key.
@note If @a key is not found in the object, then it is silently added to
the object and filled with a `null` value to make `key` a valid reference.
In case the value was `null` before, it is converted to an object.
@param[in] key key of the element to access
@return reference to the element at key @a key
@throw std::domain_error if JSON is not an object or null; example:
`"cannot use operator[] with null"`
@complexity Logarithmic in the size of the container.
@liveexample{The example below shows how object elements can be read and
written using the [] operator.,operatorarray__key_type}
@sa @ref at(const typename object_t::key_type&) for access by reference
with range checking
@sa @ref value() for access by value with a default value
@since version 1.0.1
*/
template<typename T>
reference operator[](T* key)
{
// implicitly convert null to object
if (is_null())
...
...
@@ -3111,8 +3179,6 @@ class basic_json
@warning If the element with key @a key does not exist, the behavior is
undefined.
@note This function is required for compatibility reasons with Clang.
@param[in] key key of the element to access
@return const reference to the element at key @a key
...
...
@@ -3129,10 +3195,10 @@ class basic_json
with range checking
@sa @ref value() for access by value with a default value
@since version 1.0.
0
@since version 1.0.
1
*/
template<typename T
, std::size_t n
>
const_reference operator[](
const T (&key)[n]
) const
template<typename T>
const_reference operator[](
T* key
) const
{
// at only works for objects
if (is_object())
...
...
test/unit.cpp
View file @
21a44da8
...
...
@@ -11504,4 +11504,52 @@ TEST_CASE("regression tests")
{
CHECK
(
json
::
parse
(
"
\"\\
ud80c
\\
udc60abc
\"
"
).
get
<
json
::
string_t
>
()
==
u8"\U00013060abc"
);
}
SECTION
(
"issue #144 - Cannot index by key of type static constexpr const char*"
)
{
json
j
;
// Non-const access with key as "char []"
char
array_key
[]
=
"Key1"
;
CHECK_NOTHROW
(
j
[
array_key
]
=
1
);
CHECK
(
j
[
array_key
]
==
json
(
1
));
// Non-const access with key as "const char[]"
const
char
const_array_key
[]
=
"Key2"
;
CHECK_NOTHROW
(
j
[
const_array_key
]
=
2
);
CHECK
(
j
[
const_array_key
]
==
json
(
2
));
// Non-const access with key as "char *"
char
_ptr_key
[]
=
"Key3"
;
char
*
ptr_key
=
&
_ptr_key
[
0
];
CHECK_NOTHROW
(
j
[
ptr_key
]
=
3
);
CHECK
(
j
[
ptr_key
]
==
json
(
3
));
// Non-const access with key as "const char *"
const
char
*
const_ptr_key
=
"Key4"
;
CHECK_NOTHROW
(
j
[
const_ptr_key
]
=
4
);
CHECK
(
j
[
const_ptr_key
]
==
json
(
4
));
// Non-const access with key as "static constexpr const char *"
static
constexpr
const
char
*
constexpr_ptr_key
=
"Key5"
;
CHECK_NOTHROW
(
j
[
constexpr_ptr_key
]
=
5
);
CHECK
(
j
[
constexpr_ptr_key
]
==
json
(
5
));
const
json
j_const
=
j
;
// Const access with key as "char []"
CHECK
(
j_const
[
array_key
]
==
json
(
1
));
// Const access with key as "const char[]"
CHECK
(
j_const
[
const_array_key
]
==
json
(
2
));
//Const access with key as "char *"
CHECK
(
j_const
[
ptr_key
]
==
json
(
3
));
// Const access with key as "const char *"
CHECK
(
j_const
[
const_ptr_key
]
==
json
(
4
));
// Const access with key as "static constexpr const char *"
CHECK
(
j_const
[
constexpr_ptr_key
]
==
json
(
5
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment