All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
nlohmann::detail::serializer< BasicJsonType > Class Template Reference

#include <json.hpp>

Public Member Functions

 serializer (output_adapter_t< char > s, const char ichar, error_handler_t error_handler_=error_handler_t::strict)
 
 serializer (const serializer &)=delete
 
serializeroperator= (const serializer &)=delete
 
 serializer (serializer &&)=delete
 
serializeroperator= (serializer &&)=delete
 
 ~serializer ()=default
 
void dump (const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
 internal implementation of the serialization function More...
 

Private Types

using string_t = typename BasicJsonType::string_t
 
using number_float_t = typename BasicJsonType::number_float_t
 
using number_integer_t = typename BasicJsonType::number_integer_t
 
using number_unsigned_t = typename BasicJsonType::number_unsigned_t
 

Private Member Functions

void dump_escaped (const string_t &s, const bool ensure_ascii)
 dump escaped string More...
 
unsigned int count_digits (number_unsigned_t x) noexcept
 count digits More...
 
template<typename NumberType , detail::enable_if_t< std::is_same< NumberType, number_unsigned_t >::value orstd::is_same< NumberType, number_integer_t >::value, int > = 0>
void dump_integer (NumberType x)
 dump an integer More...
 
void dump_float (number_float_t x)
 dump a floating-point number More...
 
void dump_float (number_float_t x, std::true_type)
 
void dump_float (number_float_t x, std::false_type)
 
number_unsigned_t remove_sign (number_unsigned_t x)
 
number_unsigned_t remove_sign (number_integer_t x) noexcept
 

Static Private Member Functions

static std::uint8_t decode (std::uint8_t &state, std::uint32_t &codep, const std::uint8_t byte) noexcept
 check whether a string is UTF-8 encoded More...
 

Private Attributes

output_adapter_t< char > o = nullptr
 the output of the serializer More...
 
std::array< char, 64 > number_buffer {{}}
 a (hopefully) large enough character buffer More...
 
const std::lconv * loc = nullptr
 the locale More...
 
const char thousands_sep = '\0'
 the locale's thousand separator character More...
 
const char decimal_point = '\0'
 the locale's decimal point character More...
 
std::array< char, 512 > string_buffer {{}}
 string buffer More...
 
const char indent_char
 the indentation character More...
 
string_t indent_string
 the indentation string More...
 
const error_handler_t error_handler
 error_handler how to react on decoding errors More...
 

Static Private Attributes

static constexpr std::uint8_t UTF8_ACCEPT = 0
 
static constexpr std::uint8_t UTF8_REJECT = 1
 

Detailed Description

template<typename BasicJsonType>
class nlohmann::detail::serializer< BasicJsonType >

Definition at line 13787 of file json.hpp.

Member Typedef Documentation

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::number_float_t = typename BasicJsonType::number_float_t
private

Definition at line 13790 of file json.hpp.

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::number_integer_t = typename BasicJsonType::number_integer_t
private

Definition at line 13791 of file json.hpp.

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::number_unsigned_t = typename BasicJsonType::number_unsigned_t
private

Definition at line 13792 of file json.hpp.

template<typename BasicJsonType >
using nlohmann::detail::serializer< BasicJsonType >::string_t = typename BasicJsonType::string_t
private

Definition at line 13789 of file json.hpp.

Constructor & Destructor Documentation

template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::serializer ( output_adapter_t< char >  s,
const char  ichar,
error_handler_t  error_handler_ = error_handler_t::strict 
)
inline
Parameters
[in]soutput stream to serialize to
[in]icharindentation character to use
[in]error_handler_how to react on decoding errors

Definition at line 13802 of file json.hpp.

13804  : o(std::move(s))
13805  , loc(std::localeconv())
13806  , thousands_sep(loc->thousands_sep == nullptr ? '\0' : * (loc->thousands_sep))
13807  , decimal_point(loc->decimal_point == nullptr ? '\0' : * (loc->decimal_point))
13808  , indent_char(ichar)
13809  , indent_string(512, indent_char)
13810  , error_handler(error_handler_)
13811  {}
const char indent_char
the indentation character
Definition: json.hpp:14603
const char decimal_point
the locale&#39;s decimal point character
Definition: json.hpp:14597
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition: json.hpp:14608
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
const std::lconv * loc
the locale
Definition: json.hpp:14593
const char thousands_sep
the locale&#39;s thousand separator character
Definition: json.hpp:14595
string_t indent_string
the indentation string
Definition: json.hpp:14605
template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::serializer ( const serializer< BasicJsonType > &  )
delete
template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::serializer ( serializer< BasicJsonType > &&  )
delete
template<typename BasicJsonType >
nlohmann::detail::serializer< BasicJsonType >::~serializer ( )
default

Member Function Documentation

template<typename BasicJsonType >
unsigned int nlohmann::detail::serializer< BasicJsonType >::count_digits ( number_unsigned_t  x)
inlineprivatenoexcept

count digits

Count the number of decimal (base 10) digits for an input unsigned integer.

Parameters
[in]xunsigned integer number to count its digits
Returns
number of decimal digits

Definition at line 14303 of file json.hpp.

14304  {
14305  unsigned int n_digits = 1;
14306  for (;;)
14307  {
14308  if (x < 10)
14309  {
14310  return n_digits;
14311  }
14312  if (x < 100)
14313  {
14314  return n_digits + 1;
14315  }
14316  if (x < 1000)
14317  {
14318  return n_digits + 2;
14319  }
14320  if (x < 10000)
14321  {
14322  return n_digits + 3;
14323  }
14324  x = x / 10000u;
14325  n_digits += 4;
14326  }
14327  }
process_name opflash particleana ie x
template<typename BasicJsonType >
static std::uint8_t nlohmann::detail::serializer< BasicJsonType >::decode ( std::uint8_t &  state,
std::uint32_t &  codep,
const std::uint8_t  byte 
)
inlinestaticprivatenoexcept

check whether a string is UTF-8 encoded

The function checks each byte of a string whether it is UTF-8 encoded. The result of the check is stored in the state parameter. The function must be called initially with state 0 (accept). State 1 means the string must be rejected, because the current byte is not allowed. If the string is completely processed, but the state is non-zero, the string ended prematurely; that is, the last byte indicated more bytes should have followed.

Parameters
[in,out]statethe state of the decoding
[in,out]codepcodepoint (valid only if resulting state is UTF8_ACCEPT)
[in]bytenext byte to decode
Returns
new state
Note
The function has been edited: a std::array is used.
See Also
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/

Definition at line 14527 of file json.hpp.

14528  {
14529  static const std::array<std::uint8_t, 400> utf8d =
14530  {
14531  {
14532  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F
14533  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F
14534  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F
14535  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F
14536  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F
14537  7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF
14538  8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF
14539  0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF
14540  0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF
14541  0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0
14542  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2
14543  1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4
14544  1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6
14545  1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8
14546  }
14547  };
14548 
14549  const std::uint8_t type = utf8d[byte];
14550 
14551  codep = (state != UTF8_ACCEPT)
14552  ? (byte & 0x3fu) | (codep << 6u)
14553  : (0xFFu >> type) & (byte);
14554 
14555  state = utf8d[256u + state * 16u + type];
14556  return state;
14557  }
static constexpr std::uint8_t UTF8_ACCEPT
Definition: json.hpp:13793
byte_as<> byte
Type of data size stored in bytes, in long long precision.
Definition: datasize.h:98
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump ( const BasicJsonType &  val,
const bool  pretty_print,
const bool  ensure_ascii,
const unsigned int  indent_step,
const unsigned int  current_indent = 0 
)
inline

internal implementation of the serialization function

This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively.

  • strings and object keys are escaped using escape_string()
  • integer numbers are converted implicitly via operator<<
  • floating-point numbers are converted to a string using "%g" format
Parameters
[in]valvalue to serialize
[in]pretty_printwhether the output shall be pretty-printed
[in]indent_stepthe indent level
[in]current_indentthe current indent level (only used internally)

Definition at line 13837 of file json.hpp.

13841  {
13842  switch (val.m_type)
13843  {
13844  case value_t::object:
13845  {
13846  if (val.m_value.object->empty())
13847  {
13848  o->write_characters("{}", 2);
13849  return;
13850  }
13851 
13852  if (pretty_print)
13853  {
13854  o->write_characters("{\n", 2);
13855 
13856  // variable to hold indentation for recursive calls
13857  const auto new_indent = current_indent + indent_step;
13858  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
13859  {
13860  indent_string.resize(indent_string.size() * 2, ' ');
13861  }
13862 
13863  // first n-1 elements
13864  auto i = val.m_value.object->cbegin();
13865  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
13866  {
13867  o->write_characters(indent_string.c_str(), new_indent);
13868  o->write_character('\"');
13869  dump_escaped(i->first, ensure_ascii);
13870  o->write_characters("\": ", 3);
13871  dump(i->second, true, ensure_ascii, indent_step, new_indent);
13872  o->write_characters(",\n", 2);
13873  }
13874 
13875  // last element
13876  assert(i != val.m_value.object->cend());
13877  assert(std::next(i) == val.m_value.object->cend());
13878  o->write_characters(indent_string.c_str(), new_indent);
13879  o->write_character('\"');
13880  dump_escaped(i->first, ensure_ascii);
13881  o->write_characters("\": ", 3);
13882  dump(i->second, true, ensure_ascii, indent_step, new_indent);
13883 
13884  o->write_character('\n');
13885  o->write_characters(indent_string.c_str(), current_indent);
13886  o->write_character('}');
13887  }
13888  else
13889  {
13890  o->write_character('{');
13891 
13892  // first n-1 elements
13893  auto i = val.m_value.object->cbegin();
13894  for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i)
13895  {
13896  o->write_character('\"');
13897  dump_escaped(i->first, ensure_ascii);
13898  o->write_characters("\":", 2);
13899  dump(i->second, false, ensure_ascii, indent_step, current_indent);
13900  o->write_character(',');
13901  }
13902 
13903  // last element
13904  assert(i != val.m_value.object->cend());
13905  assert(std::next(i) == val.m_value.object->cend());
13906  o->write_character('\"');
13907  dump_escaped(i->first, ensure_ascii);
13908  o->write_characters("\":", 2);
13909  dump(i->second, false, ensure_ascii, indent_step, current_indent);
13910 
13911  o->write_character('}');
13912  }
13913 
13914  return;
13915  }
13916 
13917  case value_t::array:
13918  {
13919  if (val.m_value.array->empty())
13920  {
13921  o->write_characters("[]", 2);
13922  return;
13923  }
13924 
13925  if (pretty_print)
13926  {
13927  o->write_characters("[\n", 2);
13928 
13929  // variable to hold indentation for recursive calls
13930  const auto new_indent = current_indent + indent_step;
13931  if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent))
13932  {
13933  indent_string.resize(indent_string.size() * 2, ' ');
13934  }
13935 
13936  // first n-1 elements
13937  for (auto i = val.m_value.array->cbegin();
13938  i != val.m_value.array->cend() - 1; ++i)
13939  {
13940  o->write_characters(indent_string.c_str(), new_indent);
13941  dump(*i, true, ensure_ascii, indent_step, new_indent);
13942  o->write_characters(",\n", 2);
13943  }
13944 
13945  // last element
13946  assert(not val.m_value.array->empty());
13947  o->write_characters(indent_string.c_str(), new_indent);
13948  dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent);
13949 
13950  o->write_character('\n');
13951  o->write_characters(indent_string.c_str(), current_indent);
13952  o->write_character(']');
13953  }
13954  else
13955  {
13956  o->write_character('[');
13957 
13958  // first n-1 elements
13959  for (auto i = val.m_value.array->cbegin();
13960  i != val.m_value.array->cend() - 1; ++i)
13961  {
13962  dump(*i, false, ensure_ascii, indent_step, current_indent);
13963  o->write_character(',');
13964  }
13965 
13966  // last element
13967  assert(not val.m_value.array->empty());
13968  dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent);
13969 
13970  o->write_character(']');
13971  }
13972 
13973  return;
13974  }
13975 
13976  case value_t::string:
13977  {
13978  o->write_character('\"');
13979  dump_escaped(*val.m_value.string, ensure_ascii);
13980  o->write_character('\"');
13981  return;
13982  }
13983 
13984  case value_t::boolean:
13985  {
13986  if (val.m_value.boolean)
13987  {
13988  o->write_characters("true", 4);
13989  }
13990  else
13991  {
13992  o->write_characters("false", 5);
13993  }
13994  return;
13995  }
13996 
13998  {
13999  dump_integer(val.m_value.number_integer);
14000  return;
14001  }
14002 
14004  {
14005  dump_integer(val.m_value.number_unsigned);
14006  return;
14007  }
14008 
14009  case value_t::number_float:
14010  {
14011  dump_float(val.m_value.number_float);
14012  return;
14013  }
14014 
14015  case value_t::discarded:
14016  {
14017  o->write_characters("<discarded>", 11);
14018  return;
14019  }
14020 
14021  case value_t::null:
14022  {
14023  o->write_characters("null", 4);
14024  return;
14025  }
14026 
14027  default: // LCOV_EXCL_LINE
14028  assert(false); // LCOV_EXCL_LINE
14029  }
14030  }
array (ordered collection of values)
number value (signed integer)
void dump_integer(NumberType x)
dump an integer
Definition: json.hpp:14342
void dump(const BasicJsonType &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
internal implementation of the serialization function
Definition: json.hpp:13837
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
object (unordered set of name/value pairs)
void dump_float(number_float_t x)
dump a floating-point number
Definition: json.hpp:14428
void dump_escaped(const string_t &s, const bool ensure_ascii)
dump escaped string
Definition: json.hpp:14047
number value (unsigned integer)
string_t indent_string
the indentation string
Definition: json.hpp:14605
number value (floating-point)
#define JSON_HEDLEY_UNLIKELY(expr)
Definition: json.hpp:1124
discarded by the the parser callback function
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_escaped ( const string_t s,
const bool  ensure_ascii 
)
inlineprivate

dump escaped string

Escape a string by replacing certain special characters by a sequence of an escape character (backslash) and another character and other control characters by a sequence of "\u" followed by a four-digit hex representation. The escaped string is written to output stream o.

Parameters
[in]sthe string to escape
[in]ensure_asciiwhether to escape non-ASCII characters with sequences

Linear in the length of string s.

Definition at line 14047 of file json.hpp.

14048  {
14049  std::uint32_t codepoint;
14050  std::uint8_t state = UTF8_ACCEPT;
14051  std::size_t bytes = 0; // number of bytes written to string_buffer
14052 
14053  // number of bytes written at the point of the last valid byte
14054  std::size_t bytes_after_last_accept = 0;
14055  std::size_t undumped_chars = 0;
14056 
14057  for (std::size_t i = 0; i < s.size(); ++i)
14058  {
14059  const auto byte = static_cast<uint8_t>(s[i]);
14060 
14061  switch (decode(state, codepoint, byte))
14062  {
14063  case UTF8_ACCEPT: // decode found a new code point
14064  {
14065  switch (codepoint)
14066  {
14067  case 0x08: // backspace
14068  {
14069  string_buffer[bytes++] = '\\';
14070  string_buffer[bytes++] = 'b';
14071  break;
14072  }
14073 
14074  case 0x09: // horizontal tab
14075  {
14076  string_buffer[bytes++] = '\\';
14077  string_buffer[bytes++] = 't';
14078  break;
14079  }
14080 
14081  case 0x0A: // newline
14082  {
14083  string_buffer[bytes++] = '\\';
14084  string_buffer[bytes++] = 'n';
14085  break;
14086  }
14087 
14088  case 0x0C: // formfeed
14089  {
14090  string_buffer[bytes++] = '\\';
14091  string_buffer[bytes++] = 'f';
14092  break;
14093  }
14094 
14095  case 0x0D: // carriage return
14096  {
14097  string_buffer[bytes++] = '\\';
14098  string_buffer[bytes++] = 'r';
14099  break;
14100  }
14101 
14102  case 0x22: // quotation mark
14103  {
14104  string_buffer[bytes++] = '\\';
14105  string_buffer[bytes++] = '\"';
14106  break;
14107  }
14108 
14109  case 0x5C: // reverse solidus
14110  {
14111  string_buffer[bytes++] = '\\';
14112  string_buffer[bytes++] = '\\';
14113  break;
14114  }
14115 
14116  default:
14117  {
14118  // escape control characters (0x00..0x1F) or, if
14119  // ensure_ascii parameter is used, non-ASCII characters
14120  if ((codepoint <= 0x1F) or (ensure_ascii and (codepoint >= 0x7F)))
14121  {
14122  if (codepoint <= 0xFFFF)
14123  {
14124  (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x",
14125  static_cast<std::uint16_t>(codepoint));
14126  bytes += 6;
14127  }
14128  else
14129  {
14130  (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x",
14131  static_cast<std::uint16_t>(0xD7C0u + (codepoint >> 10u)),
14132  static_cast<std::uint16_t>(0xDC00u + (codepoint & 0x3FFu)));
14133  bytes += 12;
14134  }
14135  }
14136  else
14137  {
14138  // copy byte to buffer (all previous bytes
14139  // been copied have in default case above)
14140  string_buffer[bytes++] = s[i];
14141  }
14142  break;
14143  }
14144  }
14145 
14146  // write buffer and reset index; there must be 13 bytes
14147  // left, as this is the maximal number of bytes to be
14148  // written ("\uxxxx\uxxxx\0") for one code point
14149  if (string_buffer.size() - bytes < 13)
14150  {
14151  o->write_characters(string_buffer.data(), bytes);
14152  bytes = 0;
14153  }
14154 
14155  // remember the byte position of this accept
14156  bytes_after_last_accept = bytes;
14157  undumped_chars = 0;
14158  break;
14159  }
14160 
14161  case UTF8_REJECT: // decode found invalid UTF-8 byte
14162  {
14163  switch (error_handler)
14164  {
14166  {
14167  std::string sn(3, '\0');
14168  (std::snprintf)(&sn[0], sn.size(), "%.2X", byte);
14169  JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn));
14170  }
14171 
14174  {
14175  // in case we saw this character the first time, we
14176  // would like to read it again, because the byte
14177  // may be OK for itself, but just not OK for the
14178  // previous sequence
14179  if (undumped_chars > 0)
14180  {
14181  --i;
14182  }
14183 
14184  // reset length buffer to the last accepted index;
14185  // thus removing/ignoring the invalid characters
14186  bytes = bytes_after_last_accept;
14187 
14189  {
14190  // add a replacement character
14191  if (ensure_ascii)
14192  {
14193  string_buffer[bytes++] = '\\';
14194  string_buffer[bytes++] = 'u';
14195  string_buffer[bytes++] = 'f';
14196  string_buffer[bytes++] = 'f';
14197  string_buffer[bytes++] = 'f';
14198  string_buffer[bytes++] = 'd';
14199  }
14200  else
14201  {
14205  }
14206 
14207  // write buffer and reset index; there must be 13 bytes
14208  // left, as this is the maximal number of bytes to be
14209  // written ("\uxxxx\uxxxx\0") for one code point
14210  if (string_buffer.size() - bytes < 13)
14211  {
14212  o->write_characters(string_buffer.data(), bytes);
14213  bytes = 0;
14214  }
14215 
14216  bytes_after_last_accept = bytes;
14217  }
14218 
14219  undumped_chars = 0;
14220 
14221  // continue processing the string
14222  state = UTF8_ACCEPT;
14223  break;
14224  }
14225 
14226  default: // LCOV_EXCL_LINE
14227  assert(false); // LCOV_EXCL_LINE
14228  }
14229  break;
14230  }
14231 
14232  default: // decode found yet incomplete multi-byte code point
14233  {
14234  if (not ensure_ascii)
14235  {
14236  // code point will not be escaped - copy byte to buffer
14237  string_buffer[bytes++] = s[i];
14238  }
14239  ++undumped_chars;
14240  break;
14241  }
14242  }
14243  }
14244 
14245  // we finished processing the string
14246  if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT))
14247  {
14248  // write buffer
14249  if (bytes > 0)
14250  {
14251  o->write_characters(string_buffer.data(), bytes);
14252  }
14253  }
14254  else
14255  {
14256  // we finish reading, but do not accept: string was incomplete
14257  switch (error_handler)
14258  {
14260  {
14261  std::string sn(3, '\0');
14262  (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast<std::uint8_t>(s.back()));
14263  JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn));
14264  }
14265 
14267  {
14268  // write all accepted bytes
14269  o->write_characters(string_buffer.data(), bytes_after_last_accept);
14270  break;
14271  }
14272 
14274  {
14275  // write all accepted bytes
14276  o->write_characters(string_buffer.data(), bytes_after_last_accept);
14277  // add a replacement character
14278  if (ensure_ascii)
14279  {
14280  o->write_characters("\\ufffd", 6);
14281  }
14282  else
14283  {
14284  o->write_characters("\xEF\xBF\xBD", 3);
14285  }
14286  break;
14287  }
14288 
14289  default: // LCOV_EXCL_LINE
14290  assert(false); // LCOV_EXCL_LINE
14291  }
14292  }
14293  }
static constexpr std::uint8_t UTF8_ACCEPT
Definition: json.hpp:13793
std::array< char, 512 > string_buffer
string buffer
Definition: json.hpp:14600
static constexpr std::uint8_t UTF8_REJECT
Definition: json.hpp:13794
ignore invalid UTF-8 sequences
throw a type_error exception in case of invalid UTF-8
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
#define JSON_THROW(exception)
Definition: json.hpp:1754
const error_handler_t error_handler
error_handler how to react on decoding errors
Definition: json.hpp:14608
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
#define JSON_HEDLEY_LIKELY(expr)
Definition: json.hpp:1123
std::string to_string(WindowPattern const &pattern)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
byte_as<> byte
Type of data size stored in bytes, in long long precision.
Definition: datasize.h:98
replace invalid UTF-8 sequences with U+FFFD
static constexpr CharType to_char_type(std::uint8_t x) noexcept
Definition: json.hpp:12585
byte bytes
Alias for common language habits.
Definition: datasize.h:101
static type_error create(int id_, const std::string &what_arg)
Definition: json.hpp:2078
static std::uint8_t decode(std::uint8_t &state, std::uint32_t &codep, const std::uint8_t byte) noexcept
check whether a string is UTF-8 encoded
Definition: json.hpp:14527
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_float ( number_float_t  x)
inlineprivate

dump a floating-point number

Dump a given floating-point number to output stream o. Works internally with number_buffer.

Parameters
[in]xfloating-point number to dump

Definition at line 14428 of file json.hpp.

14429  {
14430  // NaN / inf
14431  if (not std::isfinite(x))
14432  {
14433  o->write_characters("null", 4);
14434  return;
14435  }
14436 
14437  // If number_float_t is an IEEE-754 single or double precision number,
14438  // use the Grisu2 algorithm to produce short numbers which are
14439  // guaranteed to round-trip, using strtof and strtod, resp.
14440  //
14441  // NB: The test below works if <long double> == <double>.
14442  static constexpr bool is_ieee_single_or_double
14443  = (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 24 and std::numeric_limits<number_float_t>::max_exponent == 128) or
14444  (std::numeric_limits<number_float_t>::is_iec559 and std::numeric_limits<number_float_t>::digits == 53 and std::numeric_limits<number_float_t>::max_exponent == 1024);
14445 
14446  dump_float(x, std::integral_constant<bool, is_ieee_single_or_double>());
14447  }
process_name opflash particleana ie x
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
bool isfinite(Vector const &v)
Returns whether all components of the vector are finite.
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
void dump_float(number_float_t x)
dump a floating-point number
Definition: json.hpp:14428
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_float ( number_float_t  x,
std::true_type   
)
inlineprivate

Definition at line 14449 of file json.hpp.

14450  {
14451  char* begin = number_buffer.data();
14452  char* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x);
14453 
14454  o->write_characters(begin, static_cast<size_t>(end - begin));
14455  }
process_name opflash particleana ie x
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:14590
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
auto begin(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:573
JSON_HEDLEY_RETURNS_NON_NULL char * to_chars(char *first, const char *last, FloatType value)
generates a decimal representation of the floating-point number value in [first, last).
Definition: json.hpp:13709
template<typename BasicJsonType >
void nlohmann::detail::serializer< BasicJsonType >::dump_float ( number_float_t  x,
std::false_type   
)
inlineprivate

Definition at line 14457 of file json.hpp.

14458  {
14459  // get number of digits for a float -> text -> float round-trip
14460  static constexpr auto d = std::numeric_limits<number_float_t>::max_digits10;
14461 
14462  // the actual conversion
14463  std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x);
14464 
14465  // negative value indicates an error
14466  assert(len > 0);
14467  // check if buffer was large enough
14468  assert(static_cast<std::size_t>(len) < number_buffer.size());
14469 
14470  // erase thousands separator
14471  if (thousands_sep != '\0')
14472  {
14473  const auto end = std::remove(number_buffer.begin(),
14474  number_buffer.begin() + len, thousands_sep);
14475  std::fill(end, number_buffer.end(), '\0');
14476  assert((end - number_buffer.begin()) <= len);
14477  len = (end - number_buffer.begin());
14478  }
14479 
14480  // convert decimal point to '.'
14481  if (decimal_point != '\0' and decimal_point != '.')
14482  {
14483  const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point);
14484  if (dec_pos != number_buffer.end())
14485  {
14486  *dec_pos = '.';
14487  }
14488  }
14489 
14490  o->write_characters(number_buffer.data(), static_cast<std::size_t>(len));
14491 
14492  // determine if need to append ".0"
14493  const bool value_is_int_like =
14494  std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1,
14495  [](char c)
14496  {
14497  return c == '.' or c == 'e';
14498  });
14499 
14500  if (value_is_int_like)
14501  {
14502  o->write_characters(".0", 2);
14503  }
14504  }
process_name opflash particleana ie x
const char decimal_point
the locale&#39;s decimal point character
Definition: json.hpp:14597
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:14590
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
auto end(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:585
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
const char thousands_sep
the locale&#39;s thousand separator character
Definition: json.hpp:14595
template<typename BasicJsonType >
template<typename NumberType , detail::enable_if_t< std::is_same< NumberType, number_unsigned_t >::value orstd::is_same< NumberType, number_integer_t >::value, int > = 0>
void nlohmann::detail::serializer< BasicJsonType >::dump_integer ( NumberType  x)
inlineprivate

dump an integer

Dump a given integer to output stream o. Works internally with number_buffer.

Parameters
[in]xinteger number (signed or unsigned) to dump
Template Parameters
NumberTypeeither number_integer_t or number_unsigned_t

Definition at line 14342 of file json.hpp.

14343  {
14344  static constexpr std::array<std::array<char, 2>, 100> digits_to_99
14345  {
14346  {
14347  {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}},
14348  {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}},
14349  {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}},
14350  {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}},
14351  {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}},
14352  {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}},
14353  {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}},
14354  {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}},
14355  {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}},
14356  {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}},
14357  }
14358  };
14359 
14360  // special case for "0"
14361  if (x == 0)
14362  {
14363  o->write_character('0');
14364  return;
14365  }
14366 
14367  // use a pointer to fill the buffer
14368  auto buffer_ptr = number_buffer.begin();
14369 
14370  const bool is_negative = std::is_same<NumberType, number_integer_t>::value and not(x >= 0); // see issue #755
14371  number_unsigned_t abs_value;
14372 
14373  unsigned int n_chars;
14374 
14375  if (is_negative)
14376  {
14377  *buffer_ptr = '-';
14378  abs_value = remove_sign(x);
14379 
14380  // account one more byte for the minus sign
14381  n_chars = 1 + count_digits(abs_value);
14382  }
14383  else
14384  {
14385  abs_value = static_cast<number_unsigned_t>(x);
14386  n_chars = count_digits(abs_value);
14387  }
14388 
14389  // spare 1 byte for '\0'
14390  assert(n_chars < number_buffer.size() - 1);
14391 
14392  // jump to the end to generate the string from backward
14393  // so we later avoid reversing the result
14394  buffer_ptr += n_chars;
14395 
14396  // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu
14397  // See: https://www.youtube.com/watch?v=o4-CwDo2zpg
14398  while (abs_value >= 100)
14399  {
14400  const auto digits_index = static_cast<unsigned>((abs_value % 100));
14401  abs_value /= 100;
14402  *(--buffer_ptr) = digits_to_99[digits_index][1];
14403  *(--buffer_ptr) = digits_to_99[digits_index][0];
14404  }
14405 
14406  if (abs_value >= 10)
14407  {
14408  const auto digits_index = static_cast<unsigned>(abs_value);
14409  *(--buffer_ptr) = digits_to_99[digits_index][1];
14410  *(--buffer_ptr) = digits_to_99[digits_index][0];
14411  }
14412  else
14413  {
14414  *(--buffer_ptr) = static_cast<char>('0' + abs_value);
14415  }
14416 
14417  o->write_characters(number_buffer.data(), n_chars);
14418  }
process_name opflash particleana ie x
unsigned int count_digits(number_unsigned_t x) noexcept
count digits
Definition: json.hpp:14303
std::array< char, 64 > number_buffer
a (hopefully) large enough character buffer
Definition: json.hpp:14590
output_adapter_t< char > o
the output of the serializer
Definition: json.hpp:14587
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
number_unsigned_t remove_sign(number_unsigned_t x)
Definition: json.hpp:14564
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:13792
temporary value
template<typename BasicJsonType >
serializer& nlohmann::detail::serializer< BasicJsonType >::operator= ( const serializer< BasicJsonType > &  )
delete
template<typename BasicJsonType >
serializer& nlohmann::detail::serializer< BasicJsonType >::operator= ( serializer< BasicJsonType > &&  )
delete
template<typename BasicJsonType >
number_unsigned_t nlohmann::detail::serializer< BasicJsonType >::remove_sign ( number_unsigned_t  x)
inlineprivate

Definition at line 14564 of file json.hpp.

14565  {
14566  assert(false); // LCOV_EXCL_LINE
14567  return x; // LCOV_EXCL_LINE
14568  }
process_name opflash particleana ie x
template<typename BasicJsonType >
number_unsigned_t nlohmann::detail::serializer< BasicJsonType >::remove_sign ( number_integer_t  x)
inlineprivatenoexcept

Definition at line 14579 of file json.hpp.

14580  {
14581  assert(x < 0 and x < (std::numeric_limits<number_integer_t>::max)());
14582  return static_cast<number_unsigned_t>(-(x + 1)) + 1;
14583  }
process_name opflash particleana ie x
return match has_match and(match.match_pdg==11 or match.match_pdg==-11)
typename BasicJsonType::number_unsigned_t number_unsigned_t
Definition: json.hpp:13792

Member Data Documentation

template<typename BasicJsonType >
const char nlohmann::detail::serializer< BasicJsonType >::decimal_point = '\0'
private

the locale's decimal point character

Definition at line 14597 of file json.hpp.

template<typename BasicJsonType >
const error_handler_t nlohmann::detail::serializer< BasicJsonType >::error_handler
private

error_handler how to react on decoding errors

Definition at line 14608 of file json.hpp.

template<typename BasicJsonType >
const char nlohmann::detail::serializer< BasicJsonType >::indent_char
private

the indentation character

Definition at line 14603 of file json.hpp.

template<typename BasicJsonType >
string_t nlohmann::detail::serializer< BasicJsonType >::indent_string
private

the indentation string

Definition at line 14605 of file json.hpp.

template<typename BasicJsonType >
const std::lconv* nlohmann::detail::serializer< BasicJsonType >::loc = nullptr
private

the locale

Definition at line 14593 of file json.hpp.

template<typename BasicJsonType >
std::array<char, 64> nlohmann::detail::serializer< BasicJsonType >::number_buffer {{}}
private

a (hopefully) large enough character buffer

Definition at line 14590 of file json.hpp.

template<typename BasicJsonType >
output_adapter_t<char> nlohmann::detail::serializer< BasicJsonType >::o = nullptr
private

the output of the serializer

Definition at line 14587 of file json.hpp.

template<typename BasicJsonType >
std::array<char, 512> nlohmann::detail::serializer< BasicJsonType >::string_buffer {{}}
private

string buffer

Definition at line 14600 of file json.hpp.

template<typename BasicJsonType >
const char nlohmann::detail::serializer< BasicJsonType >::thousands_sep = '\0'
private

the locale's thousand separator character

Definition at line 14595 of file json.hpp.

template<typename BasicJsonType >
constexpr std::uint8_t nlohmann::detail::serializer< BasicJsonType >::UTF8_ACCEPT = 0
staticprivate

Definition at line 13793 of file json.hpp.

template<typename BasicJsonType >
constexpr std::uint8_t nlohmann::detail::serializer< BasicJsonType >::UTF8_REJECT = 1
staticprivate

Definition at line 13794 of file json.hpp.


The documentation for this class was generated from the following file: