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
9ba3f796
Commit
9ba3f796
authored
Oct 03, 2018
by
Antonio Borondo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error: explicit specialization in non-namespace scope
parent
8d1585f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
208 additions
and
196 deletions
+208
-196
input_adapters.hpp
include/nlohmann/detail/input/input_adapters.hpp
+104
-98
json.hpp
single_include/nlohmann/json.hpp
+104
-98
No files found.
include/nlohmann/detail/input/input_adapters.hpp
View file @
9ba3f796
...
@@ -142,136 +142,142 @@ class wide_string_input_adapter : public input_adapter_protocol
...
@@ -142,136 +142,142 @@ class wide_string_input_adapter : public input_adapter_protocol
template
<
size_t
T
>
template
<
size_t
T
>
void
fill_buffer
()
void
fill_buffer
()
{
{
fill_buffer_utf32
();
wide_string_input_helper
<
WideStringType
,
T
>::
fill_buffer
(
str
,
current_wchar
,
utf8_bytes
,
utf8_bytes_index
,
utf8_bytes_filled
);
}
template
<>
void
fill_buffer
<
2
>
()
{
fill_buffer_utf16
();
}
}
void
fill_buffer_utf16
()
/// the wstring to process
{
const
WideStringType
&
str
;
utf8_bytes_index
=
0
;
if
(
current_wchar
==
str
.
size
())
/// index of the current wchar in str
{
std
::
size_t
current_wchar
=
0
;
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
utf8_bytes_filled
=
1
;
/// a buffer for UTF-8 bytes
}
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>
utf8_bytes
=
{{
0
,
0
,
0
,
0
}};
else
/// index to the utf8_codes array for the next valid byte
std
::
size_t
utf8_bytes_index
=
0
;
/// number of valid bytes in the utf8_codes array
std
::
size_t
utf8_bytes_filled
=
0
;
};
namespace
{
template
<
typename
WideStringType
,
size_t
T
>
struct
wide_string_input_helper
{
// UTF-32
static
void
fill_buffer
(
const
WideStringType
&
str
,
size_t
&
current_wchar
,
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>&
utf8_bytes
,
size_t
&
utf8_bytes_index
,
size_t
&
utf8_bytes_filled
)
{
{
// get the current character
utf8_bytes_index
=
0
;
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-16 to UTF-8 encoding
if
(
current_wchar
==
str
.
size
())
if
(
wc
<
0x80
)
{
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
()
;
utf8_bytes_filled
=
1
;
utf8_bytes_filled
=
1
;
}
}
else
if
(
wc
<=
0x7FF
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
));
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
0xD800
>
wc
or
wc
>=
0xE000
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
));
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
else
{
{
if
(
current_wchar
<
str
.
size
())
// get the current character
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
if
(
wc
<
0x80
)
{
{
const
int
wc2
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
utf8_bytes
[
0
]
=
wc
;
const
int
charcode
=
0x10000
+
(((
wc
&
0x3FF
)
<<
10
)
|
(
wc2
&
0x3FF
));
utf8_bytes_filled
=
1
;
utf8_bytes
[
0
]
=
0xf0
|
(
charcode
>>
18
);
}
utf8_bytes
[
1
]
=
0x80
|
((
charcode
>>
12
)
&
0x3F
);
else
if
(
wc
<=
0x7FF
)
utf8_bytes
[
2
]
=
0x80
|
((
charcode
>>
6
)
&
0x3F
);
{
utf8_bytes
[
3
]
=
0x80
|
(
charcode
&
0x3F
);
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
)
&
0x1F
);
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
wc
<=
0xFFFF
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
)
&
0x0F
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
if
(
wc
<=
0x10FFFF
)
{
utf8_bytes
[
0
]
=
0xF0
|
((
wc
>>
18
)
&
0x07
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
12
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
3
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
4
;
utf8_bytes_filled
=
4
;
}
}
else
else
{
{
// unknown character
// unknown character
++
current_wchar
;
utf8_bytes
[
0
]
=
wc
;
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
utf8_bytes_filled
=
1
;
}
}
}
}
}
}
}
}
;
void
fill_buffer_utf32
()
template
<
typename
WideStringType
>
struct
wide_string_input_helper
<
WideStringType
,
2
>
{
{
utf8_bytes_index
=
0
;
// UTF-16
static
void
fill_buffer
(
const
WideStringType
&
str
,
size_t
&
current_wchar
,
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>&
utf8_bytes
,
size_t
&
utf8_bytes_index
,
size_t
&
utf8_bytes_filled
)
if
(
current_wchar
==
str
.
size
())
{
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
utf8_bytes_filled
=
1
;
}
else
{
{
// get the current character
utf8_bytes_index
=
0
;
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
if
(
current_wchar
==
str
.
size
())
if
(
wc
<
0x80
)
{
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
()
;
utf8_bytes_filled
=
1
;
utf8_bytes_filled
=
1
;
}
}
else
if
(
wc
<=
0x7FF
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
)
&
0x1F
);
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
wc
<=
0xFFFF
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
)
&
0x0F
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
if
(
wc
<=
0x10FFFF
)
{
utf8_bytes
[
0
]
=
0xF0
|
((
wc
>>
18
)
&
0x07
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
12
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
3
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
4
;
}
else
else
{
{
// unknown character
// get the current character
utf8_bytes
[
0
]
=
wc
;
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
utf8_bytes_filled
=
1
;
// UTF-16 to UTF-8 encoding
if
(
wc
<
0x80
)
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
else
if
(
wc
<=
0x7FF
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
));
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
0xD800
>
wc
or
wc
>=
0xE000
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
));
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
{
if
(
current_wchar
<
str
.
size
())
{
const
int
wc2
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
const
int
charcode
=
0x10000
+
(((
wc
&
0x3FF
)
<<
10
)
|
(
wc2
&
0x3FF
));
utf8_bytes
[
0
]
=
0xf0
|
(
charcode
>>
18
);
utf8_bytes
[
1
]
=
0x80
|
((
charcode
>>
12
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
((
charcode
>>
6
)
&
0x3F
);
utf8_bytes
[
3
]
=
0x80
|
(
charcode
&
0x3F
);
utf8_bytes_filled
=
4
;
}
else
{
// unknown character
++
current_wchar
;
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
}
}
}
}
}
}
};
}
private
:
/// the wstring to process
const
WideStringType
&
str
;
/// index of the current wchar in str
std
::
size_t
current_wchar
=
0
;
/// a buffer for UTF-8 bytes
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>
utf8_bytes
=
{{
0
,
0
,
0
,
0
}};
/// index to the utf8_codes array for the next valid byte
std
::
size_t
utf8_bytes_index
=
0
;
/// number of valid bytes in the utf8_codes array
std
::
size_t
utf8_bytes_filled
=
0
;
};
class
input_adapter
class
input_adapter
{
{
...
...
single_include/nlohmann/json.hpp
View file @
9ba3f796
...
@@ -2020,136 +2020,142 @@ class wide_string_input_adapter : public input_adapter_protocol
...
@@ -2020,136 +2020,142 @@ class wide_string_input_adapter : public input_adapter_protocol
template
<
size_t
T
>
template
<
size_t
T
>
void
fill_buffer
()
void
fill_buffer
()
{
{
fill_buffer_utf32
();
wide_string_input_helper
<
WideStringType
,
T
>::
fill_buffer
(
str
,
current_wchar
,
utf8_bytes
,
utf8_bytes_index
,
utf8_bytes_filled
);
}
template
<>
void
fill_buffer
<
2
>
()
{
fill_buffer_utf16
();
}
}
void
fill_buffer_utf16
()
/// the wstring to process
{
const
WideStringType
&
str
;
utf8_bytes_index
=
0
;
if
(
current_wchar
==
str
.
size
())
/// index of the current wchar in str
{
std
::
size_t
current_wchar
=
0
;
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
utf8_bytes_filled
=
1
;
/// a buffer for UTF-8 bytes
}
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>
utf8_bytes
=
{{
0
,
0
,
0
,
0
}};
else
/// index to the utf8_codes array for the next valid byte
std
::
size_t
utf8_bytes_index
=
0
;
/// number of valid bytes in the utf8_codes array
std
::
size_t
utf8_bytes_filled
=
0
;
};
namespace
{
template
<
typename
WideStringType
,
size_t
T
>
struct
wide_string_input_helper
{
// UTF-32
static
void
fill_buffer
(
const
WideStringType
&
str
,
size_t
&
current_wchar
,
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>&
utf8_bytes
,
size_t
&
utf8_bytes_index
,
size_t
&
utf8_bytes_filled
)
{
{
// get the current character
utf8_bytes_index
=
0
;
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-16 to UTF-8 encoding
if
(
current_wchar
==
str
.
size
())
if
(
wc
<
0x80
)
{
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
()
;
utf8_bytes_filled
=
1
;
utf8_bytes_filled
=
1
;
}
}
else
if
(
wc
<=
0x7FF
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
));
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
0xD800
>
wc
or
wc
>=
0xE000
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
));
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
else
{
{
if
(
current_wchar
<
str
.
size
())
// get the current character
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
if
(
wc
<
0x80
)
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
else
if
(
wc
<=
0x7FF
)
{
{
const
int
wc2
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
)
&
0x1F
);
const
int
charcode
=
0x10000
+
(((
wc
&
0x3FF
)
<<
10
)
|
(
wc2
&
0x3FF
));
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes
[
0
]
=
0xf0
|
(
charcode
>>
18
);
utf8_bytes_filled
=
2
;
utf8_bytes
[
1
]
=
0x80
|
((
charcode
>>
12
)
&
0x3F
);
}
utf8_bytes
[
2
]
=
0x80
|
((
charcode
>>
6
)
&
0x3F
);
else
if
(
wc
<=
0xFFFF
)
utf8_bytes
[
3
]
=
0x80
|
(
charcode
&
0x3F
);
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
)
&
0x0F
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
if
(
wc
<=
0x10FFFF
)
{
utf8_bytes
[
0
]
=
0xF0
|
((
wc
>>
18
)
&
0x07
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
12
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
3
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
4
;
utf8_bytes_filled
=
4
;
}
}
else
else
{
{
// unknown character
// unknown character
++
current_wchar
;
utf8_bytes
[
0
]
=
wc
;
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
utf8_bytes_filled
=
1
;
}
}
}
}
}
}
}
}
;
void
fill_buffer_utf32
()
template
<
typename
WideStringType
>
struct
wide_string_input_helper
<
WideStringType
,
2
>
{
{
utf8_bytes_index
=
0
;
// UTF-16
static
void
fill_buffer
(
const
WideStringType
&
str
,
size_t
&
current_wchar
,
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>&
utf8_bytes
,
size_t
&
utf8_bytes_index
,
size_t
&
utf8_bytes_filled
)
if
(
current_wchar
==
str
.
size
())
{
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
utf8_bytes_filled
=
1
;
}
else
{
{
// get the current character
utf8_bytes_index
=
0
;
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
if
(
current_wchar
==
str
.
size
())
if
(
wc
<
0x80
)
{
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
()
;
utf8_bytes_filled
=
1
;
utf8_bytes_filled
=
1
;
}
}
else
if
(
wc
<=
0x7FF
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
)
&
0x1F
);
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
wc
<=
0xFFFF
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
)
&
0x0F
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
if
(
wc
<=
0x10FFFF
)
{
utf8_bytes
[
0
]
=
0xF0
|
((
wc
>>
18
)
&
0x07
);
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
12
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
3
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
4
;
}
else
else
{
{
// unknown character
// get the current character
utf8_bytes
[
0
]
=
wc
;
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
utf8_bytes_filled
=
1
;
// UTF-16 to UTF-8 encoding
if
(
wc
<
0x80
)
{
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
else
if
(
wc
<=
0x7FF
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
));
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
0xD800
>
wc
or
wc
>=
0xE000
)
{
utf8_bytes
[
0
]
=
0xE0
|
((
wc
>>
12
));
utf8_bytes
[
1
]
=
0x80
|
((
wc
>>
6
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
3
;
}
else
{
if
(
current_wchar
<
str
.
size
())
{
const
int
wc2
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
const
int
charcode
=
0x10000
+
(((
wc
&
0x3FF
)
<<
10
)
|
(
wc2
&
0x3FF
));
utf8_bytes
[
0
]
=
0xf0
|
(
charcode
>>
18
);
utf8_bytes
[
1
]
=
0x80
|
((
charcode
>>
12
)
&
0x3F
);
utf8_bytes
[
2
]
=
0x80
|
((
charcode
>>
6
)
&
0x3F
);
utf8_bytes
[
3
]
=
0x80
|
(
charcode
&
0x3F
);
utf8_bytes_filled
=
4
;
}
else
{
// unknown character
++
current_wchar
;
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
}
}
}
}
}
}
};
}
private
:
/// the wstring to process
const
WideStringType
&
str
;
/// index of the current wchar in str
std
::
size_t
current_wchar
=
0
;
/// a buffer for UTF-8 bytes
std
::
array
<
std
::
char_traits
<
char
>::
int_type
,
4
>
utf8_bytes
=
{{
0
,
0
,
0
,
0
}};
/// index to the utf8_codes array for the next valid byte
std
::
size_t
utf8_bytes_index
=
0
;
/// number of valid bytes in the utf8_codes array
std
::
size_t
utf8_bytes_filled
=
0
;
};
class
input_adapter
class
input_adapter
{
{
...
...
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