Skip to content

Commit 2373ab2

Browse files
committed
writer-json-common: move number recognition to a separate fnc
1 parent 5ca302a commit 2373ab2

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: src/lib/writer-json-common.cc

+9-3
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,22 @@ std::string sanitizeUTF8(const std::string &str)
3333
return convert_string<char>(str.data(), str.data() + str.size());
3434
}
3535

36+
/// return true if the given string represents a number
37+
bool isNumber(const std::string &str)
38+
{
39+
static auto isDigit = [](unsigned char c){ return std::isdigit(c); };
40+
41+
return std::all_of(str.begin(), str.end(), isDigit);
42+
}
43+
3644
// TODO: This should not necessary! TScanProps should be able to contain
3745
// any type so that no conversions here are needed.
3846
object jsonSerializeScanProps(const TScanProps &scanProps)
3947
{
40-
static auto isDigit = [](unsigned char c){ return std::isdigit(c); };
41-
4248
object scan;
4349
for (const auto &prop : scanProps) {
4450
const auto &val = prop.second;
45-
if (std::all_of(val.begin(), val.end(), isDigit))
51+
if (isNumber(val))
4652
scan[prop.first] = boost::lexical_cast<int>(val);
4753
else
4854
scan[prop.first] = val;

0 commit comments

Comments
 (0)