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
5c7d27c3
Unverified
Commit
5c7d27c3
authored
Oct 04, 2018
by
Niels Lohmann
Committed by
GitHub
Oct 04, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1272 from antonioborondo/fix_warning
Fix warning C4127: conditional expression is constant
parents
9f18e170
b6fdad9a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
130 deletions
+148
-130
include/nlohmann/detail/input/input_adapters.hpp
include/nlohmann/detail/input/input_adapters.hpp
+73
-65
single_include/nlohmann/json.hpp
single_include/nlohmann/json.hpp
+75
-65
No files found.
include/nlohmann/detail/input/input_adapters.hpp
View file @
5c7d27c3
...
@@ -115,38 +115,66 @@ class input_buffer_adapter : public input_adapter_protocol
...
@@ -115,38 +115,66 @@ class input_buffer_adapter : public input_adapter_protocol
const
char
*
const
limit
;
const
char
*
const
limit
;
};
};
template
<
typename
WideStringType
>
template
<
typename
WideStringType
,
size_t
T
>
class
wide_string_input_adapter
:
public
input_adapter_protocol
struct
wide_string_input_helper
{
{
public:
// UTF-32
explicit
wide_string_input_adapter
(
const
WideStringType
&
w
)
:
str
(
w
)
{}
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
)
std
::
char_traits
<
char
>::
int_type
get_character
()
noexcept
override
{
{
// check if buffer needs to be filled
utf8_bytes_index
=
0
;
if
(
utf8_bytes_index
==
utf8_bytes_filled
)
if
(
current_wchar
==
str
.
size
())
{
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
utf8_bytes_filled
=
1
;
}
else
{
{
if
(
sizeof
(
typename
WideStringType
::
value_type
)
==
2
)
// 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
)
{
utf8_bytes
[
0
]
=
0xC0
|
((
wc
>>
6
)
&
0x1F
);
utf8_bytes
[
1
]
=
0x80
|
(
wc
&
0x3F
);
utf8_bytes_filled
=
2
;
}
else
if
(
wc
<=
0xFFFF
)
{
{
fill_buffer_utf16
();
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
{
{
fill_buffer_utf32
();
// unknown character
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
}
assert
(
utf8_bytes_filled
>
0
);
assert
(
utf8_bytes_index
==
0
);
}
}
// use buffer
assert
(
utf8_bytes_filled
>
0
);
assert
(
utf8_bytes_index
<
utf8_bytes_filled
);
return
utf8_bytes
[
utf8_bytes_index
++
];
}
}
};
private:
template
<
typename
WideStringType
>
void
fill_buffer_utf16
()
struct
wide_string_input_helper
<
WideStringType
,
2
>
{
// 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
)
{
{
utf8_bytes_index
=
0
;
utf8_bytes_index
=
0
;
...
@@ -201,58 +229,38 @@ class wide_string_input_adapter : public input_adapter_protocol
...
@@ -201,58 +229,38 @@ class wide_string_input_adapter : public input_adapter_protocol
}
}
}
}
}
}
};
void
fill_buffer_utf32
()
template
<
typename
WideStringType
>
{
class
wide_string_input_adapter
:
public
input_adapter_protocol
utf8_bytes_index
=
0
;
{
public:
explicit
wide_string_input_adapter
(
const
WideStringType
&
w
)
:
str
(
w
)
{}
if
(
current_wchar
==
str
.
size
())
std
::
char_traits
<
char
>::
int_type
get_character
()
noexcept
override
{
{
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
// check if buffer needs to be filled
utf8_bytes_filled
=
1
;
if
(
utf8_bytes_index
==
utf8_bytes_filled
)
}
else
{
{
// get the current character
fill_buffer
<
sizeof
(
typename
WideStringType
::
value_type
)
>
();
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
assert
(
utf8_bytes_filled
>
0
);
if
(
wc
<
0x80
)
assert
(
utf8_bytes_index
==
0
);
{
utf8_bytes
[
0
]
=
wc
;
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
{
// unknown character
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
}
}
// use buffer
assert
(
utf8_bytes_filled
>
0
);
assert
(
utf8_bytes_index
<
utf8_bytes_filled
);
return
utf8_bytes
[
utf8_bytes_index
++
];
}
}
private:
private:
template
<
size_t
T
>
void
fill_buffer
()
{
wide_string_input_helper
<
WideStringType
,
T
>::
fill_buffer
(
str
,
current_wchar
,
utf8_bytes
,
utf8_bytes_index
,
utf8_bytes_filled
);
}
/// the wstring to process
/// the wstring to process
const
WideStringType
&
str
;
const
WideStringType
&
str
;
...
...
single_include/nlohmann/json.hpp
View file @
5c7d27c3
...
@@ -1993,38 +1993,66 @@ class input_buffer_adapter : public input_adapter_protocol
...
@@ -1993,38 +1993,66 @@ class input_buffer_adapter : public input_adapter_protocol
const
char
*
const
limit
;
const
char
*
const
limit
;
};
};
template
<
typename
WideStringType
>
template
<
typename
WideStringType
,
size_t
T
>
class
wide_string_input_adapter
:
public
input_adapter_protocol
struct
wide_string_input_helper
{
{
public:
// UTF-32
explicit
wide_string_input_adapter
(
const
WideStringType
&
w
)
:
str
(
w
)
{}
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
)
std
::
char_traits
<
char
>::
int_type
get_character
()
noexcept
override
{
{
// check if buffer needs to be filled
utf8_bytes_index
=
0
;
if
(
utf8_bytes_index
==
utf8_bytes_filled
)
if
(
current_wchar
==
str
.
size
())
{
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
utf8_bytes_filled
=
1
;
}
else
{
{
if
(
sizeof
(
typename
WideStringType
::
value_type
)
==
2
)
// get the current character
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
if
(
wc
<
0x80
)
{
{
fill_buffer_utf16
();
utf8_bytes
[
0
]
=
wc
;
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
{
{
fill_buffer_utf32
();
// unknown character
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
}
assert
(
utf8_bytes_filled
>
0
);
assert
(
utf8_bytes_index
==
0
);
}
}
// use buffer
assert
(
utf8_bytes_filled
>
0
);
assert
(
utf8_bytes_index
<
utf8_bytes_filled
);
return
utf8_bytes
[
utf8_bytes_index
++
];
}
}
};
private:
template
<
typename
WideStringType
>
void
fill_buffer_utf16
()
struct
wide_string_input_helper
<
WideStringType
,
2
>
{
// 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
)
{
{
utf8_bytes_index
=
0
;
utf8_bytes_index
=
0
;
...
@@ -2079,58 +2107,38 @@ class wide_string_input_adapter : public input_adapter_protocol
...
@@ -2079,58 +2107,38 @@ class wide_string_input_adapter : public input_adapter_protocol
}
}
}
}
}
}
};
void
fill_buffer_utf32
()
template
<
typename
WideStringType
>
{
class
wide_string_input_adapter
:
public
input_adapter_protocol
utf8_bytes_index
=
0
;
{
public:
explicit
wide_string_input_adapter
(
const
WideStringType
&
w
)
:
str
(
w
)
{}
if
(
current_wchar
==
str
.
size
())
std
::
char_traits
<
char
>::
int_type
get_character
()
noexcept
override
{
{
utf8_bytes
[
0
]
=
std
::
char_traits
<
char
>::
eof
();
// check if buffer needs to be filled
utf8_bytes_filled
=
1
;
if
(
utf8_bytes_index
==
utf8_bytes_filled
)
}
else
{
{
// get the current character
fill_buffer
<
sizeof
(
typename
WideStringType
::
value_type
)
>
();
const
int
wc
=
static_cast
<
int
>
(
str
[
current_wchar
++
]);
// UTF-32 to UTF-8 encoding
assert
(
utf8_bytes_filled
>
0
);
if
(
wc
<
0x80
)
assert
(
utf8_bytes_index
==
0
);
{
utf8_bytes
[
0
]
=
wc
;
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
{
// unknown character
utf8_bytes
[
0
]
=
wc
;
utf8_bytes_filled
=
1
;
}
}
}
// use buffer
assert
(
utf8_bytes_filled
>
0
);
assert
(
utf8_bytes_index
<
utf8_bytes_filled
);
return
utf8_bytes
[
utf8_bytes_index
++
];
}
}
private:
private:
template
<
size_t
T
>
void
fill_buffer
()
{
wide_string_input_helper
<
WideStringType
,
T
>::
fill_buffer
(
str
,
current_wchar
,
utf8_bytes
,
utf8_bytes_index
,
utf8_bytes_filled
);
}
/// the wstring to process
/// the wstring to process
const
WideStringType
&
str
;
const
WideStringType
&
str
;
...
@@ -2146,6 +2154,8 @@ class wide_string_input_adapter : public input_adapter_protocol
...
@@ -2146,6 +2154,8 @@ class wide_string_input_adapter : public input_adapter_protocol
std
::
size_t
utf8_bytes_filled
=
0
;
std
::
size_t
utf8_bytes_filled
=
0
;
};
};
class
input_adapter
class
input_adapter
{
{
public:
public:
...
...
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