Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
f75e195d
Unverified
Commit
f75e195d
authored
Mar 26, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
added code for user-defined number types
parent
34255279
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
11 deletions
+30
-11
src/json.hpp
src/json.hpp
+30
-11
No files found.
src/json.hpp
View file @
f75e195d
...
@@ -10771,6 +10771,23 @@ class basic_json
...
@@ -10771,6 +10771,23 @@ class basic_json
}
}
}
}
// overloaded wrappers for strtod/strtof/strtold
// that will be called from parse<floating_point_t>
static
void
strtof
(
float
&
f
,
const
char
*
str
,
char
**
endptr
)
noexcept
{
f
=
std
::
strtof
(
str
,
endptr
);
}
static
void
strtof
(
double
&
f
,
const
char
*
str
,
char
**
endptr
)
noexcept
{
f
=
std
::
strtod
(
str
,
endptr
);
}
static
void
strtof
(
long
double
&
f
,
const
char
*
str
,
char
**
endptr
)
noexcept
{
f
=
std
::
strtold
(
str
,
endptr
);
}
token_type
scan_number
()
token_type
scan_number
()
{
{
static
unsigned
char
lookup
[
9
][
256
]
=
static
unsigned
char
lookup
[
9
][
256
]
=
...
@@ -10851,23 +10868,25 @@ class basic_json
...
@@ -10851,23 +10868,25 @@ class basic_json
errno
=
0
;
errno
=
0
;
if
(
has_sign
)
if
(
has_sign
)
{
{
value_integer
=
std
::
strtoll
(
yytext
.
data
(),
&
endptr
,
10
);
const
auto
x
=
std
::
strtoll
(
yytext
.
data
(),
&
endptr
,
10
);
if
(
JSON_LIKELY
(
errno
==
0
and
endptr
==
yytext
.
data
()
+
yylen
))
value_integer
=
static_cast
<
number_integer_t
>
(
x
);
if
(
JSON_LIKELY
(
errno
==
0
and
endptr
==
yytext
.
data
()
+
yylen
and
value_integer
==
x
))
{
{
return
token_type
::
value_integer
;
return
token_type
::
value_integer
;
}
}
}
}
else
else
{
{
value_unsigned
=
std
::
strtoull
(
yytext
.
data
(),
&
endptr
,
10
);
const
auto
x
=
std
::
strtoull
(
yytext
.
data
(),
&
endptr
,
10
);
if
(
JSON_LIKELY
(
errno
==
0
and
endptr
==
yytext
.
data
()
+
yylen
))
value_unsigned
=
static_cast
<
number_unsigned_t
>
(
x
);
if
(
JSON_LIKELY
(
errno
==
0
and
endptr
==
yytext
.
data
()
+
yylen
and
value_unsigned
==
x
))
{
{
return
token_type
::
value_unsigned
;
return
token_type
::
value_unsigned
;
}
}
}
}
}
}
value_float
=
std
::
strtod
(
yytext
.
data
(),
nullptr
);
strtof
(
value_float
,
yytext
.
data
(),
nullptr
);
return
token_type
::
value_float
;
return
token_type
::
value_float
;
}
}
...
@@ -10996,14 +11015,14 @@ class basic_json
...
@@ -10996,14 +11015,14 @@ class basic_json
case
lexer
:
:
token_type
::
value_unsigned
:
case
lexer
:
:
token_type
::
value_unsigned
:
{
{
result
.
m_type
=
value_t
::
number_unsigned
;
result
.
m_type
=
value_t
::
number_unsigned
;
result
.
m_value
=
static_cast
<
number_unsigned_t
>
(
value_unsigned
)
;
result
.
m_value
=
value_unsigned
;
return
true
;
return
true
;
}
}
case
lexer
:
:
token_type
::
value_integer
:
case
lexer
:
:
token_type
::
value_integer
:
{
{
result
.
m_type
=
value_t
::
number_integer
;
result
.
m_type
=
value_t
::
number_integer
;
result
.
m_value
=
static_cast
<
number_integer_t
>
(
value_integer
)
;
result
.
m_value
=
value_integer
;
return
true
;
return
true
;
}
}
...
@@ -11016,7 +11035,7 @@ class basic_json
...
@@ -11016,7 +11035,7 @@ class basic_json
}
}
result
.
m_type
=
value_t
::
number_float
;
result
.
m_type
=
value_t
::
number_float
;
result
.
m_value
=
static_cast
<
number_float_t
>
(
value_float
)
;
result
.
m_value
=
value_float
;
return
true
;
return
true
;
}
}
...
@@ -11114,9 +11133,9 @@ class basic_json
...
@@ -11114,9 +11133,9 @@ class basic_json
std
::
string
error_message
=
""
;
std
::
string
error_message
=
""
;
// number values
// number values
long
long
value_integer
=
0
;
number_integer_t
value_integer
=
0
;
unsigned
long
long
value_unsigned
=
0
;
number_unsigned_t
value_unsigned
=
0
;
double
value_float
=
0
;
number_float_t
value_float
=
0
;
// the decimal point
// the decimal point
const
char
decimal_point_char
=
'\0'
;
const
char
decimal_point_char
=
'\0'
;
...
...
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