Newer
Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
namespace MantidQt {
namespace CustomInterfaces {
bool isEntirelyWhitespace(std::string const &string) {
return std::all_of(string.cbegin(), string.cend(),
[](unsigned char c) { return std::isspace(c); });
}
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
boost::optional<double> parseDouble(std::string string) {
boost::trim(string);
auto end = std::size_t();
try {
auto result = std::stod(string, &end);
if (end == string.size())
return result;
else
return boost::none;
} catch (std::invalid_argument &) {
return boost::none;
} catch (std::out_of_range &) {
return boost::none;
}
}
boost::optional<double> parseNonNegativeDouble(std::string string) {
auto maybeNegative = parseDouble(std::move(string));
if (maybeNegative.is_initialized() && maybeNegative.get() >= 0.0)
return maybeNegative.get();
else
return boost::none;
}
boost::optional<double> parseNonNegativeNonZeroDouble(std::string string) {
auto maybeNegative = parseDouble(std::move(string));
if (maybeNegative.is_initialized() && maybeNegative.get() > 0.0)
return maybeNegative.get();
else
return boost::none;
}
boost::optional<int> parseInt(std::string string) {
boost::trim(string);
auto end = std::size_t();
try {
auto result = std::stoi(string, &end);
if (end == string.size())
return result;
else
return boost::none;
} catch (std::invalid_argument &) {
return boost::none;
} catch (std::out_of_range &) {
return boost::none;
}
}
boost::optional<int> parseNonNegativeInt(std::string string) {
auto maybeNegative = parseInt(std::move(string));
if (maybeNegative.is_initialized() && maybeNegative.get() >= 0)
return maybeNegative.get();
else
return boost::none;
}
} // namespace CustomInterfaces
} // namespace MantidQt