File tree Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Expand file tree Collapse file tree 2 files changed +8
-16
lines changed Original file line number Diff line number Diff line change 10
10
#include < json/reader.h>
11
11
#include < json/value.h>
12
12
#endif // if !defined(JSON_IS_AMALGAMATION)
13
+ #include < algorithm>
13
14
#include < cassert>
14
15
#include < cstring>
15
16
#include < iostream>
@@ -77,10 +78,7 @@ Features Features::strictMode() {
77
78
// ////////////////////////////////
78
79
79
80
bool Reader::containsNewLine (Reader::Location begin, Reader::Location end) {
80
- for (; begin < end; ++begin)
81
- if (*begin == ' \n ' || *begin == ' \r ' )
82
- return true ;
83
- return false ;
81
+ return std::any_of (begin, end, [](char b) { return b == ' \n ' || b == ' \r ' ; });
84
82
}
85
83
86
84
// Class Reader
@@ -998,10 +996,7 @@ class OurReader {
998
996
999
997
bool OurReader::containsNewLine (OurReader::Location begin,
1000
998
OurReader::Location end) {
1001
- for (; begin < end; ++begin)
1002
- if (*begin == ' \n ' || *begin == ' \r ' )
1003
- return true ;
1004
- return false ;
999
+ return std::any_of (begin, end, [](char b) { return b == ' \n ' || b == ' \r ' ; });
1005
1000
}
1006
1001
1007
1002
OurReader::OurReader (OurFeatures const & features) : features_(features) {}
Original file line number Diff line number Diff line change 7
7
#include " json_tool.h"
8
8
#include < json/writer.h>
9
9
#endif // if !defined(JSON_IS_AMALGAMATION)
10
+ #include < algorithm>
10
11
#include < cassert>
12
+ #include < cctype>
11
13
#include < cstring>
12
14
#include < iomanip>
13
15
#include < memory>
@@ -176,14 +178,9 @@ String valueToString(bool value) { return value ? "true" : "false"; }
176
178
static bool isAnyCharRequiredQuoting (char const * s, size_t n) {
177
179
assert (s || !n);
178
180
179
- char const * const end = s + n;
180
- for (char const * cur = s; cur < end; ++cur) {
181
- if (*cur == ' \\ ' || *cur == ' \" ' ||
182
- static_cast <unsigned char >(*cur) < ' ' ||
183
- static_cast <unsigned char >(*cur) >= 0x80 )
184
- return true ;
185
- }
186
- return false ;
181
+ return std::any_of (s, s + n, [](int c) {
182
+ return c == ' \\ ' || c == ' "' || !std::isprint (c);
183
+ });
187
184
}
188
185
189
186
static unsigned int utf8ToCodepoint (const char *& s, const char * e) {
You can’t perform that action at this time.
0 commit comments