9 #include "cetlib/canonical_number.h" 10 #include "cetlib/canonical_string.h" 19 using namespace fhicl;
22 using boost::lexical_cast;
23 using boost::numeric_cast;
29 static inline std::string
32 static std::string
const canon_nil(9,
'\0');
65 result = any_cast<std::string>(a);
85 bool is_quoted = value.size() >= 2 && value[0] == value.end()[-1] &&
86 (value[0] ==
'\"' || value[0] ==
'\'');
88 std::string
const& str = is_quoted ? value :
'\'' + value +
'\'';
94 << str <<
"\nat or before:\n" 103 return encode(std::string(value));
127 std::string result = lexical_cast<std::string>(
value);
128 if (result.size() > 6) {
129 std::size_t sz = result.size() - 1;
130 result.insert(1,
".");
131 result +=
"e+" + lexical_cast<std::string>(sz);
141 result.insert(0,
"-");
148 if (value == std::numeric_limits<ldbl>::infinity())
150 if (value == -std::numeric_limits<ldbl>::infinity())
153 std::intmax_t chopped =
static_cast<std::intmax_t
>(
value);
154 if (static_cast<ldbl>(chopped) ==
value)
158 cet::canonical_number(lexical_cast<std::string>(value), result);
171 if (result.size() >= 2 && result[0] ==
'\"' && result.end()[-1] ==
'\"')
172 result = cet::unescape(result.substr(1, result.size() - 2));
194 std::string unparsed;
197 << str <<
"\nat or before:\n" 218 std::string unparsed;
221 << str <<
"\nat or before:\n" 225 ldbl via = lexical_cast<
ldbl>(atom);
226 result = numeric_cast<std::uintmax_t>(via);
227 if (via !=
ldbl(result))
228 throw std::range_error(
"narrowing conversion");
238 std::string unparsed;
241 << str <<
"\nat or before:\n" 245 ldbl via = lexical_cast<
ldbl>(atom);
246 result = numeric_cast<std::intmax_t>(via);
247 if (via !=
ldbl(result))
248 throw std::range_error(
"narrowing conversion");
258 std::string unparsed;
261 << str <<
"\nat or before:\n" 268 result = +std::numeric_limits<ldbl>::infinity();
271 result = -std::numeric_limits<ldbl>::infinity();
275 result = lexical_cast<
ldbl>(atom);
285 std::string unparsed;
288 << str <<
"\nat or before:\n" 293 decode(cmplx.first, real);
294 decode(cmplx.second, imag);
295 result = {real, imag};
static ParameterSetID const & put(ParameterSet const &ps)
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
bool is_a(value_tag const t) const noexcept
ps_atom_t encode(std::string const &)
static ps_atom_t literal_false()
static collection_type const & get() noexcept
constexpr auto abs(T v)
Returns the absolute value of the argument.
std::pair< std::string, std::string > complex_t
void decode(std::any const &, std::string &)
static ps_atom_t literal_true()
bool is_nil(std::any const &val)
static std::string canon_nil()
static ps_atom_t literal_infinity()
static void atom_rep(any const &a, std::string &result)
bool is_table(std::any const &val)
cet::coded_exception< error, detail::translate > exception
bool is_sequence(std::any const &val)