9 #include "cetlib/canonical_number.h" 10 #include "cetlib/canonical_string.h" 19 using namespace fhicl;
23 using boost::any_cast;
24 using boost::lexical_cast;
25 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);
67 if( result.size() >= 2 && result[0] ==
'\"' && result.end()[-1] ==
'\"' )
68 result = cet::unescape( result.substr(1, result.size()-2) );
89 bool is_quoted = value.size() >= 2 && value[0] == value.end()[-1] &&
90 (value[0] ==
'\"' || value[0] ==
'\'');
92 std::string
const& str = is_quoted ? value :
'\'' + value +
'\'';
98 << str <<
"\nat or before:\n" 107 return encode(std::string(value));
131 std::string result = lexical_cast<std::string>(
value);
132 if (result.size() > 6) {
133 std::size_t sz = result.size() - 1;
134 result.insert(1,
".");
135 result +=
"e+" + lexical_cast<std::string>(sz);
143 std::string result =
encode(std::uintmax_t(std::abs(value)));
145 result.insert(0,
"-");
152 if (value == std::numeric_limits<ldbl>::infinity())
154 if (value == -std::numeric_limits<ldbl>::infinity())
157 std::intmax_t chopped =
static_cast<std::intmax_t
>(
value);
158 if (static_cast<ldbl>(chopped) ==
value)
162 cet::canonical_number(lexical_cast<std::string>(value), result);
175 if (result.size() >= 2 && result[0] ==
'\"' && result.end()[-1] ==
'\"')
176 result = cet::unescape(result.substr(1, result.size() - 2));
198 std::string unparsed;
201 << str <<
"\nat or before:\n" 205 atom_t
const& atom =
atom_t(xval);
223 std::string unparsed;
226 << str <<
"\nat or before:\n" 230 atom_t
const& atom =
atom_t(xval);
231 ldbl via = lexical_cast<
ldbl>(atom);
232 result = numeric_cast<std::uintmax_t>(via);
233 if (via !=
ldbl(result))
234 throw std::range_error(
"narrowing conversion");
244 std::string unparsed;
247 << str <<
"\nat or before:\n" 251 atom_t
const& atom =
atom_t(xval);
252 ldbl via = lexical_cast<
ldbl>(atom);
253 result = numeric_cast<std::intmax_t>(via);
254 if (via !=
ldbl(result))
255 throw std::range_error(
"narrowing conversion");
265 std::string unparsed;
268 << str <<
"\nat or before:\n" 272 atom_t
const& atom =
atom_t(xval);
276 result = +std::numeric_limits<ldbl>::infinity();
279 result = -std::numeric_limits<ldbl>::infinity();
283 result = lexical_cast<
ldbl>(atom);
293 std::string unparsed;
296 << str <<
"\nat or before:\n" 300 complex_t
const& cmplx =
complex_t(xval);
302 decode(cmplx.first, real);
303 decode(cmplx.second, imag);
304 result = std::complex<ldbl>(real, imag);
intermediate_table::complex_t complex_t
void decode(boost::any const &, std::string &)
static ParameterSetID const & put(ParameterSet const &ps)
bool parse_value_string(std::string const &s, extended_value &v, std::string &unparsed)
ps_atom_t encode(std::string const &)
static ps_atom_t literal_false()
bool is_nil(boost::any const &val)
static collection_type const & get() noexcept
bool is_sequence(boost::any const &val)
bool is_table(boost::any const &val)
std::pair< std::string, std::string > complex_t
static ps_atom_t literal_true()
bool is_a(value_tag t) const
static std::string canon_nil()
static ps_atom_t literal_infinity()
intermediate_table::atom_t atom_t
std::string value(boost::any const &)
static void atom_rep(any const &a, std::string &result)
cet::coded_exception< error, detail::translate > exception