rapidyaml  0.16.0
parseandemitYAML,anddoitfast
c4::yml Namespace Reference

Namespaces

 detail
 
 extra
 

Classes

struct  as_json
 tag type to mark a tree or node to be emitted as yaml when using operator<<, with options. More...
 
struct  as_yaml
 tag type to mark a tree or node to be emitted as yaml when using operator<< . More...
 
struct  Callbacks
 A c-style callbacks class to customize behavior on errors or allocation. More...
 
class  ConstNodeRef
 Holds a pointer to an existing tree, and a node id. More...
 
struct  EmitOptions
 A lightweight object containing options to be used when emitting. More...
 
class  Emitter
 A YAML/JSON emitter, templated on a writer class such as WriterBuf, WriterFile, or WriterOStream. More...
 
struct  ErrorDataBasic
 Data for a basic error. More...
 
struct  ErrorDataParse
 Data for a parse error. More...
 
struct  ErrorDataVisit
 Data for a visit error. More...
 
struct  escaped_scalar
 formatting helper to escape a scalar with escape_scalar_fn() More...
 
struct  EventHandlerStack
 Use this class a base of implementations of event handler to simplify the stack logic. More...
 
struct  EventHandlerTree
 The event handler to create a ryml Tree. More...
 
struct  ExceptionBasic
 Exception thrown by the default basic error implementation. More...
 
struct  ExceptionParse
 Exception thrown by the default parse error implementation. More...
 
struct  ExceptionVisit
 Exception thrown by the default visit error implementation. More...
 
struct  FilterProcessorInplaceEndExtending
 Filters in place. More...
 
struct  FilterProcessorInplaceMidExtending
 Filters in place. More...
 
struct  FilterProcessorSrcDst
 Filters an input string into a different output string. More...
 
struct  FilterResult
 Result for filtering a scalar which not fit in the intended memory. More...
 
struct  FilterResultExtending
 Result for filtering a scalar which not fit in the intended memory. More...
 
struct  LineContents
 Helper to control the line contents while parsing a buffer. More...
 
struct  Location
 holds a source or yaml file position, for example when an error is detected; See also location_format() and location_format_with_context(). More...
 
struct  NodeData
 contains the data for each YAML node. More...
 
class  NodeRef
 A reference to a node in an existing yaml tree, offering a more convenient API than the index-based API used in the tree. More...
 
struct  NodeScalar
 a node scalar is a csubstr, which may be tagged and anchored. More...
 
struct  NodeType
 Wraps a type_bits mask of NodeTypeBits flags with some syntactic sugar and predicates. More...
 
class  ParseEngine
 This is the main driver of parsing logic: it scans the YAML or JSON source for tokens, and emits the appropriate sequence of parsing events to its event handler. More...
 
struct  ParserOptions
 Options to give to the ParseEngine to control its behavior. More...
 
struct  ParserState
 
struct  ReadResult
 A lightweight truthy type, used to enable reporting the offending node when a deserializing error happens in nested reads. More...
 
struct  ReferenceResolver
 Reusable object to resolve references/aliases in a Tree. More...
 
struct  TagCache
 Accelerator structure to reduce memory requirements by enabling reuse of resolved tags. More...
 
struct  TagDirective
 
struct  TagDirectiveRange
 
struct  TagDirectives
 
class  Tree
 
struct  WriterBuf
 A writer to a memory buffer, in the form of a substr . More...
 
struct  WriterFile
 A writer that outputs to a C file handle, defaulting to stdout. More...
 
struct  WriterOStream
 A writer that outputs to an STL-like ostream. More...
 

Typedefs

using id_type = RYML_ID_TYPE
 The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE to a suitable integer type. More...
 
typedef enum c4::yml::Encoding_ Encoding_e
 
using pfn_allocate = void *(*)(size_t len, void *hint, void *user_data)
 the type of the function used to allocate memory; ryml will only allocate memory through this callback. More...
 
using pfn_free = void(*)(void *mem, size_t size, void *user_data)
 the type of the function used to free memory; ryml will only free memory through this callback. More...
 
using pfn_error_basic = void(*)(csubstr msg, ErrorDataBasic const &errdata, void *user_data)
 the type of the function used to report basic errors. More...
 
using pfn_error_parse = void(*)(csubstr msg, ErrorDataParse const &errdata, void *user_data)
 the type of the function used to report parse errors. More...
 
using pfn_error_visit = void(*)(csubstr msg, ErrorDataVisit const &errdata, void *user_data)
 the type of the function used to report visit errors. More...
 
using EmitterBuf = Emitter< WriterBuf >
 
using EmitterFile = Emitter< WriterFile >
 
template<class OStream >
using EmitterOStream = Emitter< WriterOStream< OStream >>
 
using Parser = ParseEngine< EventHandlerTree >
 This is the main ryml parser, where the parser events are handled to create a ryml tree (see Event Handlers). More...
 
using type_bits = uint32_t
 the integral type necessary to cover all the bits for NodeType_e More...
 
using ParserFlag_t = int
 data type for ParserState_e More...
 
using tag_bits = uint16_t
 the integral type necessary to cover all the bits marking node tags More...
 

Enumerations

enum  : id_type { NONE = id_type(-1) }
 
enum  : size_t { npos = size_t(-1) }
 
enum  Encoding_ {
  NOBOM, UTF8, UTF16LE, UTF16BE,
  UTF32LE, UTF32BE
}
 
enum  NodeTypeBits : type_bits {
  NOTYPE = 0, KEY = b_(0), VAL = b_(1), MAP = b_(2),
  SEQ = b_(3), DOC = b_(4), STREAM = b_(5)|SEQ, KEYREF = b_(6),
  VALREF = b_(7), KEYANCH = b_(8), VALANCH = b_(9), KEYTAG = b_(10),
  VALTAG = b_(11), KEYNIL = b_(12), VALNIL = b_(13), TYMASK_ = b_(14)-1,
  KEY_UNFILT = b_(14), VAL_UNFILT = b_(15), FLOW_SL = b_(16), FLOW_ML1 = b_(17),
  FLOW_MLN = b_(18), FLOW_SPC = b_(19), BLOCK = b_(20), KEY_LITERAL = b_(21),
  VAL_LITERAL = b_(22), KEY_FOLDED = b_(23), VAL_FOLDED = b_(24), KEY_SQUO = b_(25),
  VAL_SQUO = b_(26), KEY_DQUO = b_(27), VAL_DQUO = b_(28), KEY_PLAIN = b_(29),
  VAL_PLAIN = b_(30), KEYVAL = KEY|VAL, KEYSEQ = KEY|SEQ, KEYMAP = KEY|MAP,
  DOCMAP = DOC|MAP, DOCSEQ = DOC|SEQ, DOCVAL = DOC|VAL, SCALAR_LITERAL = KEY_LITERAL|VAL_LITERAL,
  SCALAR_FOLDED = KEY_FOLDED|VAL_FOLDED, SCALAR_SQUO = KEY_SQUO|VAL_SQUO, SCALAR_DQUO = KEY_DQUO|VAL_DQUO, SCALAR_PLAIN = KEY_PLAIN|VAL_PLAIN,
  KEYQUO = KEY_SQUO|KEY_DQUO|KEY_FOLDED|KEY_LITERAL, VALQUO = VAL_SQUO|VAL_DQUO|VAL_FOLDED|VAL_LITERAL, KEY_STYLE = KEYQUO|KEY_PLAIN, VAL_STYLE = VALQUO|VAL_PLAIN,
  SCALAR_STYLE = KEY_STYLE|VAL_STYLE, FLOW_MLX = FLOW_ML1|FLOW_MLN, CONTAINER_STYLE_FLOW = FLOW_SL|FLOW_MLX|FLOW_SPC, CONTAINER_STYLE_BLOCK = BLOCK,
  CONTAINER_STYLE = CONTAINER_STYLE_FLOW|CONTAINER_STYLE_BLOCK, STYLE = SCALAR_STYLE | CONTAINER_STYLE
}
 a bit mask for marking node types and styles More...
 
enum  ParserState_e : ParserFlag_t {
  RTOP = 0x01 << 0, RUNK = 0x01 << 1, RMAP = 0x01 << 2, RSEQ = 0x01 << 3,
  RFLOW = 0x01 << 4, RBLCK = 0x01 << 5, QMRK = 0x01 << 6, RKEY = 0x01 << 7,
  RVAL = 0x01 << 9, RKCL = 0x01 << 8, RNXT = 0x01 << 10, SSCL = 0x01 << 11,
  QSCL = 0x01 << 12, RSET = 0x01 << 13, RDOC = 0x01 << 14, NDOC = 0x01 << 15,
  USTY = 0x01 << 16, RSEQIMAP = 0x01 << 17
}
 Enumeration of the state flags for the parser. More...
 
enum  YamlTag_e : tag_bits {
  TAG_NONE = 0, TAG_MAP = 1, TAG_OMAP = 2, TAG_PAIRS = 3,
  TAG_SET = 4, TAG_SEQ = 5, TAG_BINARY = 6, TAG_BOOL = 7,
  TAG_FLOAT = 8, TAG_INT = 9, TAG_MERGE = 10, TAG_NULL = 11,
  TAG_STR = 12, TAG_TIMESTAMP = 13, TAG_VALUE = 14, TAG_YAML = 15
}
 a bit mask for marking tags for types More...
 

Functions

void set_callbacks (Callbacks const &c)
 set the global callbacks for the library; after a call to this function, these callbacks will be used by newly created objects (unless they are copying older objects with different callbacks). More...
 
Callbacks const & get_callbacks ()
 get the global callbacks More...
 
void reset_callbacks ()
 set the global callbacks back to their defaults. More...
 
void err_basic (ErrorDataBasic const &errdata, const char *msg)
 trigger a basic error to its respective handler, with a non-formatted error message. More...
 
void err_basic (Callbacks const &callbacks, ErrorDataBasic const &errdata, const char *msg_)
 trigger a basic error to its respective handler, with a non-formatted error message. More...
 
void err_parse (ErrorDataParse const &errdata, const char *msg)
 trigger a parse error to its respective handler, with a non-formatted error message. More...
 
void err_parse (Callbacks const &callbacks, ErrorDataParse const &errdata, const char *msg)
 trigger a parse error to its respective handler, with a non-formatted error message More...
 
void err_visit (ErrorDataVisit const &errdata, const char *msg)
 trigger a visit error to its respective handler, with a non-formatted error message. More...
 
void err_visit (Callbacks const &callbacks, ErrorDataVisit const &errdata, const char *msg)
 trigger a visit error to its respective handler, with a non-formatted error message More...
 
substr emit_yaml (Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit YAML to the given buffer. More...
 
substr emit_yaml (Tree const &t, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr emit_json (Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit JSON to the given buffer. More...
 
substr emit_json (Tree const &t, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr emit_yaml (Tree const &t, id_type id, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit YAML to the given buffer. More...
 
substr emit_yaml (Tree const &t, id_type id, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr emit_json (Tree const &t, id_type id, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit JSON to the given buffer. More...
 
substr emit_json (Tree const &t, id_type id, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr emit_yaml (ConstNodeRef const &r, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit YAML to the given buffer. More...
 
substr emit_yaml (ConstNodeRef const &r, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr emit_json (ConstNodeRef const &r, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit JSON to the given buffer. More...
 
substr emit_json (ConstNodeRef const &r, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr emitrs_yaml (Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: emit YAML to the given std::string/std::vector<char>-like container, resizing it as needed to fit the emitted YAML. More...
 
template<class CharOwningContainer >
substr emitrs_yaml (Tree const &t, id_type id, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr emitrs_json (Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: emit JSON to the given std::string/std::vector<char>-like container, resizing it as needed to fit the emitted JSON. More...
 
template<class CharOwningContainer >
substr emitrs_json (Tree const &t, id_type id, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
CharOwningContainer emitrs_yaml (Tree const &t, id_type id, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector<char>-like container. More...
 
template<class CharOwningContainer >
CharOwningContainer emitrs_json (Tree const &t, id_type id, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector<char>-like container. More...
 
template<class CharOwningContainer >
substr emitrs_yaml (Tree const &t, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: YAML to the given std::string/std::vector<char>-like container, resizing it as needed to fit the emitted YAML. More...
 
template<class CharOwningContainer >
substr emitrs_yaml (Tree const &t, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr emitrs_json (Tree const &t, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: JSON to the given std::string/std::vector<char>-like container, resizing it as needed to fit the emitted JSON. More...
 
template<class CharOwningContainer >
substr emitrs_json (Tree const &t, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
CharOwningContainer emitrs_yaml (Tree const &t, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector<char>-like container. More...
 
template<class CharOwningContainer >
CharOwningContainer emitrs_json (Tree const &t, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector<char>-like container. More...
 
template<class CharOwningContainer >
substr emitrs_yaml (ConstNodeRef const &n, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: YAML to the given std::string/std::vector<char>-like container, resizing it as needed to fit the emitted YAML. More...
 
template<class CharOwningContainer >
substr emitrs_yaml (ConstNodeRef const &n, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr emitrs_json (ConstNodeRef const &n, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: JSON to the given std::string/std::vector<char>-like container, resizing it as needed to fit the emitted JSON. More...
 
template<class CharOwningContainer >
substr emitrs_json (ConstNodeRef const &n, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
CharOwningContainer emitrs_yaml (ConstNodeRef const &n, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector<char>-like container. More...
 
template<class CharOwningContainer >
CharOwningContainer emitrs_json (ConstNodeRef const &n, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector<char>-like container. More...
 
void emit_yaml (Tree const &t, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit YAML to the given file, starting at the root node. More...
 
void emit_yaml (Tree const &t, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
void emit_json (Tree const &t, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit JSON to the given file. More...
 
void emit_json (Tree const &t, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
void emit_yaml (Tree const &t, id_type id, EmitOptions const &opts, FILE *f)
 (1) emit YAML to the given file, starting at the given node. More...
 
void emit_yaml (Tree const &t, id_type id, FILE *f)
 (2) like (1), but use default emit options More...
 
void emit_json (Tree const &t, id_type id, EmitOptions const &opts, FILE *f)
 (1) emit JSON to the given file, starting at the given node. More...
 
void emit_json (Tree const &t, id_type id, FILE *f)
 (2) like (1), but use default emit options More...
 
void emit_yaml (ConstNodeRef const &r, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit YAML to the given file. More...
 
void emit_yaml (ConstNodeRef const &r, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
void emit_json (ConstNodeRef const &r, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit JSON to the given file. More...
 
void emit_json (ConstNodeRef const &r, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
template<class OStream >
OStream & operator<< (OStream &stream, Tree const &tree)
 emit YAML to an STL-like ostream More...
 
template<class OStream >
OStream & operator<< (OStream &stream, ConstNodeRef const &node)
 emit YAML to an STL-like ostream More...
 
template<class OStream >
OStream & operator<< (OStream &stream, as_json const &json_spec)
 emit JSON to an STL-like ostream More...
 
template<class OStream >
OStream & operator<< (OStream &stream, as_yaml const &yaml_spec)
 emit YAML to an STL-like ostream More...
 
template<class DumpFn >
size_t location_format (DumpFn &&dumpfn, Location const &loc)
 generic formatting of a location More...
 
template<class DumpFn >
void location_format_with_context (DumpFn &&dumpfn, Location const &location, csubstr source_buffer, csubstr call="", size_t num_lines_before=3, size_t num_lines_after=0, size_t first_col_highlight=0, size_t last_col_highlight=0, size_t maxlen=80u)
 Generic formatting of a location, printing the source code buffer region around the location. More...
 
template<class DumpFn >
void err_basic_format (DumpFn &&dumpfn, csubstr msg, ErrorDataBasic const &errdata)
 Given an error message and associated basic error data, format it fully as a basic error message. More...
 
template<class DumpFn >
void err_parse_format (DumpFn &&dumpfn, csubstr msg, ErrorDataParse const &errdata)
 Given an error message and associated parse error data, format it fully as a parse error message. More...
 
template<class DumpFn >
void err_visit_format (DumpFn &&dumpfn, csubstr msg, ErrorDataVisit const &errdata)
 Given an error message and associated visit error data, format it fully as a visit error message. More...
 
template<class... Args>
void err_basic (Callbacks const &callbacks, ErrorDataBasic const &errdata, const char *fmt, Args const &...args)
 trigger a basic error to its respective handler, with a formatted error message. More...
 
template<class... Args>
void err_basic (ErrorDataBasic const &errdata, const char *fmt, Args const &...args)
 trigger a basic error to its respective handler, with a formatted error message. More...
 
template<class... Args>
void err_parse (Callbacks const &callbacks, ErrorDataParse const &errdata, const char *fmt, Args const &...args)
 trigger a parse error to its respective handler, with a formatted error message More...
 
template<class... Args>
void err_parse (ErrorDataParse const &errdata, const char *fmt, Args const &...args)
 trigger a parse error to its respective handler, with a formatted error message. More...
 
template<class... Args>
void err_visit (Callbacks const &callbacks, ErrorDataVisit const &errdata, const char *fmt, Args const &...args)
 trigger a visit error to its respective handler, with a formatted error message More...
 
template<class... Args>
void err_visit (ErrorDataVisit const &errdata, const char *fmt, Args const &...args)
 trigger a visit error to its respective handler, with a formatted error message. More...
 
template<class CharContainer >
void format_exc (CharContainer *out, ExceptionBasic const &exc)
 Format a basic exception to an existing char container. More...
 
template<class CharContainer >
void format_exc (CharContainer *out, ExceptionParse const &exc)
 Format a parse exception to an existing char container. More...
 
template<class CharContainer >
void format_exc (CharContainer *out, ExceptionVisit const &exc)
 Format a visit exception to an existing char container. More...
 
template<class CharContainer , class ExceptionT >
CharContainer format_exc (ExceptionT const &exc)
 Format a parse exception, and return a newly-created char container. More...
 
template<class Fn >
void escape_scalar_fn (Fn &&fn, csubstr scalar, bool keep_newlines=false)
 Iterate through a scalar and escape special characters in it. More...
 
size_t adjust_pos_with_escapes (csubstr scalar, size_t pos, bool keep_newlines=false)
 Adjust a position in a scalar, increasing it to account for any escaped characters. More...
 
size_t escape_scalar (substr buffer, csubstr scalar, bool keep_newlines=false)
 Escape a scalar to an existing buffer, using escape_scalar_fn. More...
 
size_t to_chars (substr buf, escaped_scalar e)
 formatting implementation to escape a scalar with escape_scalar() More...
 
template<class SinkPfn >
size_t dump (SinkPfn &&sinkfn, substr buf, escaped_scalar const &e)
 dumping implementation to escape a scalar with escape_scalar_fn() More...
 
void file_put_contents (void const *buf, size_t sz, FILE *file, const char *filename=nullptr)
 save a contiguous buffer into a file More...
 
template<class ContiguousContainer >
void file_put_contents (ContiguousContainer const &v, FILE *file, const char *filename=nullptr)
 save a contiguous buffer into a file More...
 
void file_put_contents (void const *buf, size_t sz, const char *filename, const char *access="wb")
 save a contiguous buffer into a file More...
 
template<class ContiguousContainer >
void file_put_contents (ContiguousContainer const &v, const char *filename, const char *access="wb")
 save a contiguous buffer into a file More...
 
void file_get_contents (const char *filename, FILE *fp, size_t filesz, void *buf, size_t bufsz)
 load a file of specified size from disk into an existing contiguous buffer. More...
 
size_t file_get_contents (const char *filename, FILE *fp, void *buf, size_t bufsz)
 load a file from disk into an existing contiguous buffer. More...
 
size_t file_get_contents (const char *filename, void *buf, size_t bufsz, const char *access="rb")
 load a file from disk into an existing contiguous buffer. More...
 
template<class ContiguousContainer >
void file_get_contents (ContiguousContainer *v, const char *filename, const char *access="rb")
 load a file from disk into an existing ContiguousContainer, resizing it to fit the file's contents More...
 
template<class ContiguousContainer >
ContiguousContainer file_get_contents (const char *filename, const char *access="rb")
 load a file from disk and return a newly created ContiguousContainer with the file contents More...
 
template<class ContiguousContainer >
void stdin_get_contents (ContiguousContainer *cont, FILE *f=stdin)
 load a file from stdin (or similar stream-like file) and return a newly created ContiguousContainer with the file contents More...
 
template<class ContiguousContainer >
ContiguousContainer stdin_get_contents (FILE *f=stdin)
 load a file from stdin and return a newly created ContiguousContainer with the file contents More...
 
template<class T >
ReadResult read (ConstNodeRef const &n, T *v)
 
template<class T >
ReadResult read (ConstNodeRef const &n, T const &wrapper)
 
template<class T >
ReadResult read_key (ConstNodeRef const &n, T *v)
 
template<class T >
ReadResult read_key (ConstNodeRef const &n, T const &wrapper)
 
template<class T >
void write (NodeRef *n, T const &v)
 
template<class T >
void write_key (NodeRef *n, T const &v)
 
template<class T >
void write (NodeRef &n, T const &v)
 
template<class T >
void write_key (NodeRef &n, T const &v)
 
void parse_in_place (Parser *parser, csubstr filename, substr yaml, Tree *t, id_type node_id)
 (1) parse YAML into an existing tree node. More...
 
void parse_in_place (Parser *parser, substr yaml, Tree *t, id_type node_id)
 (2) like (1) but no filename will be reported More...
 
void parse_in_place (Parser *parser, csubstr filename, substr yaml, Tree *t)
 (3) parse YAML into the root node of an existing tree. More...
 
void parse_in_place (Parser *parser, substr yaml, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_in_place (Parser *parser, csubstr filename, substr yaml, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_in_place (Parser *parser, substr yaml, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_in_place (Parser *parser, csubstr filename, substr yaml)
 (7) create a new tree, and parse YAML into its root node. More...
 
Tree parse_in_place (Parser *parser, substr yaml)
 (8) like (7) but no filename will be reported More...
 
void parse_in_place (csubstr filename, substr yaml, Tree *t, id_type node_id, ParserOptions const &opts={})
 (1) parse YAML into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_in_place (substr yaml, Tree *t, id_type node_id, ParserOptions const &opts={})
 (2) like (1) but no filename will be reported More...
 
void parse_in_place (csubstr filename, substr yaml, Tree *t, ParserOptions const &opts={})
 (3) parse YAML into an existing tree, into its root node. More...
 
void parse_in_place (substr yaml, Tree *t, ParserOptions const &opts={})
 (4) like (3) but no filename will be reported More...
 
void parse_in_place (csubstr filename, substr yaml, NodeRef node, ParserOptions const &opts={})
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_in_place (substr yaml, NodeRef node, ParserOptions const &opts={})
 (6) like (5) but no filename will be reported More...
 
Tree parse_in_place (csubstr filename, substr yaml, ParserOptions const &opts={})
 (7) create a new tree, and parse YAML into its root node. More...
 
Tree parse_in_place (substr yaml, ParserOptions const &opts={})
 (8) like (7) but no filename will be reported More...
 
void parse_json_in_place (Parser *parser, csubstr filename, substr json, Tree *t, id_type node_id)
 (1) parse JSON into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_json_in_place (Parser *parser, substr json, Tree *t, id_type node_id)
 (2) like (1) but no filename will be reported More...
 
void parse_json_in_place (Parser *parser, csubstr filename, substr json, Tree *t)
 (3) parse JSON into an existing tree, into its root node. More...
 
void parse_json_in_place (Parser *parser, substr json, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_json_in_place (Parser *parser, csubstr filename, substr json, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_json_in_place (Parser *parser, substr json, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_json_in_place (Parser *parser, csubstr filename, substr json)
 (7) create a new tree, and parse JSON into its root node. More...
 
Tree parse_json_in_place (Parser *parser, substr json)
 (8) like (7) but no filename will be reported More...
 
void parse_json_in_place (csubstr filename, substr json, Tree *t, id_type node_id, ParserOptions const &opts={})
 (1) parse JSON into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_json_in_place (substr json, Tree *t, id_type node_id, ParserOptions const &opts={})
 (2) like (1) but no filename will be reported More...
 
void parse_json_in_place (csubstr filename, substr json, Tree *t, ParserOptions const &opts={})
 (3) parse JSON into an existing tree, into its root node. More...
 
void parse_json_in_place (substr json, Tree *t, ParserOptions const &opts={})
 (4) like (3) but no filename will be reported More...
 
void parse_json_in_place (csubstr filename, substr json, NodeRef node, ParserOptions const &opts={})
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_json_in_place (substr json, NodeRef node, ParserOptions const &opts={})
 (6) like (5) but no filename will be reported More...
 
Tree parse_json_in_place (csubstr filename, substr json, ParserOptions const &opts={})
 (7) create a new tree, and parse JSON into its root node. More...
 
Tree parse_json_in_place (substr json, ParserOptions const &opts={})
 (8) like (7) but no filename will be reported More...
 
void parse_in_arena (Parser *parser, csubstr filename, csubstr yaml, Tree *t, id_type node_id)
 (1) parse YAML into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_in_arena (Parser *parser, csubstr yaml, Tree *t, id_type node_id)
 (2) like (1) but no filename will be reported More...
 
void parse_in_arena (Parser *parser, csubstr filename, csubstr yaml, Tree *t)
 (3) parse YAML into an existing tree, into its root node. More...
 
void parse_in_arena (Parser *parser, csubstr yaml, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_in_arena (Parser *parser, csubstr filename, csubstr yaml, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_in_arena (Parser *parser, csubstr yaml, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_in_arena (Parser *parser, csubstr filename, csubstr yaml)
 (7) create a new tree, and parse YAML into its root node. More...
 
Tree parse_in_arena (Parser *parser, csubstr yaml)
 (8) like (7) but no filename will be reported More...
 
void parse_in_arena (csubstr filename, csubstr yaml, Tree *t, id_type node_id, ParserOptions const &opts={})
 (1) parse YAML into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_in_arena (csubstr yaml, Tree *t, id_type node_id, ParserOptions const &opts={})
 (2) like (1) but no filename will be reported More...
 
void parse_in_arena (csubstr filename, csubstr yaml, Tree *t, ParserOptions const &opts={})
 (3) parse YAML into an existing tree, into its root node. More...
 
void parse_in_arena (csubstr yaml, Tree *t, ParserOptions const &opts={})
 (4) like (3) but no filename will be reported More...
 
void parse_in_arena (csubstr filename, csubstr yaml, NodeRef node, ParserOptions const &opts={})
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_in_arena (csubstr yaml, NodeRef node, ParserOptions const &opts={})
 (6) like (5) but no filename will be reported More...
 
Tree parse_in_arena (csubstr filename, csubstr yaml, ParserOptions const &opts={})
 (7) create a new tree, and parse YAML into its root node. More...
 
Tree parse_in_arena (csubstr yaml, ParserOptions const &opts={})
 (8) like (7) but no filename will be reported More...
 
void parse_json_in_arena (Parser *parser, csubstr filename, csubstr json, Tree *t, id_type node_id)
 (1) parse JSON into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_json_in_arena (Parser *parser, csubstr json, Tree *t, id_type node_id)
 (2) like (1) but no filename will be reported More...
 
void parse_json_in_arena (Parser *parser, csubstr filename, csubstr json, Tree *t)
 (3) parse JSON into an existing tree, into its root node. More...
 
void parse_json_in_arena (Parser *parser, csubstr json, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_json_in_arena (Parser *parser, csubstr filename, csubstr json, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_json_in_arena (Parser *parser, csubstr json, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_json_in_arena (Parser *parser, csubstr filename, csubstr json)
 (7) create a new tree, and parse JSON into its root node. More...
 
Tree parse_json_in_arena (Parser *parser, csubstr json)
 (8) like (7) but no filename will be reported More...
 
void parse_json_in_arena (csubstr filename, csubstr json, Tree *t, id_type node_id, ParserOptions const &opts={})
 (1) parse JSON into an existing tree node. The filename will be used in any error messages arising during the parse. More...
 
void parse_json_in_arena (csubstr json, Tree *t, id_type node_id, ParserOptions const &opts={})
 (2) like (1) but no filename will be reported More...
 
void parse_json_in_arena (csubstr filename, csubstr json, Tree *t, ParserOptions const &opts={})
 (3) parse JSON into an existing tree, into its root node. More...
 
void parse_json_in_arena (csubstr json, Tree *t, ParserOptions const &opts={})
 (4) like (3) but no filename will be reported More...
 
void parse_json_in_arena (csubstr filename, csubstr json, NodeRef node, ParserOptions const &opts={})
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_json_in_arena (csubstr json, NodeRef node, ParserOptions const &opts={})
 (6) like (5) but no filename will be reported More...
 
Tree parse_json_in_arena (csubstr filename, csubstr json, ParserOptions const &opts={})
 (7) create a new tree, and parse JSON into its root node. More...
 
Tree parse_json_in_arena (csubstr json, ParserOptions const &opts={})
 (8) like (7) but no filename will be reported More...
 
id_type estimate_tree_capacity (csubstr src)
 Quickly inspect the source to estimate the number of nodes the resulting tree is likely to have. More...
 
bool scalar_is_null (csubstr s) noexcept
 YAML-sense query of nullity. More...
 
bool scalar_is_plain_number_json (csubstr s) noexcept
 JSON-sense query of plain number. More...
 
bool scalar_is_inf3 (const char *s) noexcept
 Query if a scalar is inf (inf, Inf, INF) More...
 
bool scalar_is_nan3 (const char *s) noexcept
 Query if a scalar is nan (nan, NaN, Nan, NAN) More...
 
bool scalar_is_inf_or_nan3 (const char *s) noexcept
 Same as scalar_is_inf3() || scalar_is_nan3() More...
 
bool scalar_is_special_json (csubstr s) noexcept
 Query if a scalar is plain, eg, true, false, null, +-.inf or .nan. More...
 
template<class T >
bool from_chars_float (csubstr scalar, T *val) RYML_NOEXCEPT
 Deserialize a floating point from string. More...
 
template<class T >
size_t to_chars_float (substr buf, T val) RYML_NOEXCEPT
 Serialize a floating point value to a string. More...
 
template<class T >
bool from_chars_integral (csubstr scalar, T *val) RYML_NOEXCEPT
 Deserialize an integral scalar. More...
 
template<class T >
bool scalar_deserialize (csubstr str, T *val)
 Deserialize a scalar from its string representation, dispatching to one of from_chars(), from_chars_float() or from_chars_integral() as appropriate. More...
 
template<class T >
size_t scalar_serialize (substr buf, T const &a)
 Serialize a scalar to the buffer, dispatching to to_chars() or to_chars_float() as appropriate. More...
 
bool scalar_style_query_squo (csubstr scalar) noexcept
 query whether a scalar can be encoded using single quotes. More...
 
bool scalar_style_query_plain_flow (csubstr scalar) noexcept
 query whether a scalar can be encoded using plain style while in flow mode. More...
 
bool scalar_style_query_plain_block (csubstr scalar) noexcept
 query whether a scalar can be encoded using plain style while in block mode. More...
 
NodeType scalar_style_choose_block (csubstr scalar) noexcept
 choose a YAML scalar style based on the scalar's contents, while in block mode. More...
 
NodeType scalar_style_choose_json (csubstr scalar) noexcept
 choose a json scalar style based on the scalar's contents More...
 
NodeType scalar_style_choose_flow (csubstr scalar) noexcept
 choose a YAML scalar style based on the scalar's contents, while in flow mode. More...
 
template<class K , class V , class Less , class Alloc >
void write (c4::yml::Tree *tree, c4::yml::id_type id, std::map< K, V, Less, Alloc > const &m)
 serialize a map to a node: implementation for Tree More...
 
template<class K , class V , class Less , class Alloc >
void write (c4::yml::NodeRef *n, std::map< K, V, Less, Alloc > const &m)
 serialize a map to a node: implementation for NodeRef More...
 
template<class K , class V , class Less , class Alloc >
ReadResult read (c4::yml::Tree const *tree, c4::yml::id_type id, std::map< K, V, Less, Alloc > *m)
 deserialize a map from a node: implementation for Tree . More...
 
template<class K , class V , class Less , class Alloc >
ReadResult read (c4::yml::ConstNodeRef const &n, std::map< K, V, Less, Alloc > *m)
 deserialize a map from a node: implementation for ConstNodeRef . More...
 
template<class T , class Alloc >
void write (Tree *tree, id_type id, std::vector< T, Alloc > const &vec)
 serialize a vector to a node: implementation for Tree More...
 
template<class T , class Alloc >
void write (NodeRef *n, std::vector< T, Alloc > const &vec)
 serialize a vector to a node: implementation for NodeRef More...
 
template<class T , class Alloc >
ReadResult read (Tree const *tree, id_type id, std::vector< T, Alloc > *vec)
 deserialize from a Tree node, overwriting existing vector entries. More...
 
template<class T , class Alloc >
ReadResult read (ConstNodeRef const &node, std::vector< T, Alloc > *vec)
 deserialize from a ConstNodeRef node, overwriting existing vector entries. More...
 
template<class Alloc >
ReadResult read (Tree const *tree, id_type id, std::vector< bool, Alloc > *vec)
 deserialize from a Tree node, overwriting existing vector entries. More...
 
template<class Alloc >
ReadResult read (ConstNodeRef const &n, std::vector< bool, Alloc > *vec)
 deserialize from a ConstNodeRef node, overwriting existing vector entries. More...
 
bool is_custom_tag (csubstr tag)
 is a tag of the form !handle!tag? More...
 
csubstr normalize_tag (csubstr tag)
 
csubstr normalize_tag_long (csubstr tag)
 
csubstr normalize_tag_long (csubstr tag, substr output)
 
YamlTag_e to_tag (csubstr tag)
 
csubstr from_tag_long (YamlTag_e tag)
 
csubstr from_tag (YamlTag_e tag)
 
bool is_valid_tag_handle (csubstr handle)
 
size_t transform_tag (substr output, csubstr handle, csubstr prefix, csubstr tag, Callbacks const &callbacks, Location const &ymlloc={}, bool with_brackets=true)
 returns the length of the transformed tag, or 0 to signal that the tag is local and cannot be resolved More...
 
csubstr serialize_to_arena_str (Tree *tree, csubstr scalar)
 Serialize a string type (as specified by c4::is_string) to a tree's arena, ensuring that there is an entry for the string in the arena even if the string is empty. More...
 
template<class T >
csubstr serialize_to_arena_scalar (Tree *tree, T const &scalar)
 Serialize a scalar to the tree's arena. More...
 
template<class T >
csubstr serialize_to_arena (Tree *tree, T const &scalar)
 Serialize a scalar to a tree's arena, dispatching to either serialize_to_arena_scalar() or serialize_to_arena_str() when the type is a string according to c4::is_string. More...
 
csubstr serialize_to_arena (Tree *, std::nullptr_t) noexcept
 implementation for null values More...
 
template<class T >
type_bits scalar_flags_val (T const &) noexcept
 Return extra style flags to use when setting a scalar as val. More...
 
template<class T >
type_bits scalar_flags_key (T const &) noexcept
 Return extra style flags to use when setting a scalar as key. More...
 
template<class T >
void write (Tree *tree, id_type id, T const &v)
 Serialize a variable to the tree's arena, and set it as the node's val. More...
 
template<class T >
void write_key (Tree *tree, id_type id, T const &v)
 Serialize a variable to the tree's arena, and set it as the node's key. More...
 
template<class T >
ReadResult read (Tree const *tree, id_type id, T *v)
 Deserialize a scalar node's val from a tree object, returning false if the conversion failed. More...
 
template<class Wrapper >
ReadResult read (Tree const *tree, id_type id, Wrapper const &w)
 overload to enable use of wrapper tag-types like eg c4::fmt::base64() More...
 
template<class T >
ReadResult read_key (Tree const *tree, id_type id, T *v)
 Deserialize a node's key from a tree object, returning false if the conversion failed. More...
 
template<class Wrapper >
ReadResult read_key (Tree const *tree, id_type id, Wrapper const &w)
 overload to enable use of wrapper tag-types like eg c4::fmt::base64() More...
 
csubstr version ()
 
int version_major ()
 
int version_minor ()
 
int version_patch ()
 

Typedef Documentation

using c4::yml::id_type = typedef RYML_ID_TYPE

The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE to a suitable integer type.

Definition at line 124 of file common.hpp.

using c4::yml::ParserFlag_t = typedef int

data type for ParserState_e

Definition at line 14 of file parser_state.hpp.

Enumeration Type Documentation

anonymous enum : id_type
Enumerator
NONE 

an index to none

Definition at line 129 of file common.hpp.

129  : id_type { // NOLINT
130  /** an index to none */
131  NONE = id_type(-1), // NOLINT
132 };
an index to none
Definition: common.hpp:131
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
anonymous enum : size_t
Enumerator
npos 

a null string position

Definition at line 136 of file common.hpp.

136  : size_t { // NOLINT
137  /** a null string position */
138  npos = size_t(-1) // NOLINT
139 };
a null string position
Definition: common.hpp:138
Enumerator
NOBOM 

No Byte Order Mark was found.

UTF8 

UTF8.

UTF16LE 

UTF16, Little-Endian.

UTF16BE 

UTF16, Big-Endian.

UTF32LE 

UTF32, Little-Endian.

UTF32BE 

UTF32, Big-Endian.

Definition at line 142 of file common.hpp.

142  { // NOLINT
143  NOBOM, //!< No Byte Order Mark was found
144  UTF8, //!< UTF8
145  UTF16LE, //!< UTF16, Little-Endian
146  UTF16BE, //!< UTF16, Big-Endian
147  UTF32LE, //!< UTF32, Little-Endian
148  UTF32BE, //!< UTF32, Big-Endian
149 } Encoding_e;
enum c4::yml::Encoding_ Encoding_e
UTF32, Little-Endian.
Definition: common.hpp:147
UTF16, Big-Endian.
Definition: common.hpp:146
UTF8.
Definition: common.hpp:144
UTF32, Big-Endian.
Definition: common.hpp:148
No Byte Order Mark was found.
Definition: common.hpp:143
UTF16, Little-Endian.
Definition: common.hpp:145

Enumeration of the state flags for the parser.

Enumerator
RTOP 

reading at top level

RUNK 

reading unknown state (when starting): must determine whether scalar, map or seq

RMAP 

reading a map

RSEQ 

reading a seq

RFLOW 

reading is inside explicit flow chars: [] or {}

RBLCK 

reading in block mode

QMRK 

reading an explicit key (? key)

RKEY 

reading a key

RVAL 

reading a val

RKCL 

reading the key colon (ie the : after the key in the map)

RNXT 

read next sibling

SSCL 

there's a stored scalar

QSCL 

stored scalar was quoted

RSET 

the (implicit) map being read is a !!set.

See also
https://yaml.org/type/set.html
RDOC 

reading a document

NDOC 

no document mode. a document has ended and another has not started yet.

USTY 

reading in unknown style mode - must determine FLOW or BLCK reading an implicit map nested in an explicit seq. eg, {key: [key2: value2, key3: value3]} is parsed as {key: [{key2: value2}, {key3: value3}]}

RSEQIMAP 

Definition at line 17 of file parser_state.hpp.

17  : ParserFlag_t { // NOLINT
18  RTOP = 0x01 << 0, ///< reading at top level
19  RUNK = 0x01 << 1, ///< reading unknown state (when starting): must determine whether scalar, map or seq
20  RMAP = 0x01 << 2, ///< reading a map
21  RSEQ = 0x01 << 3, ///< reading a seq
22  RFLOW = 0x01 << 4, ///< reading is inside explicit flow chars: [] or {}
23  RBLCK = 0x01 << 5, ///< reading in block mode
24  QMRK = 0x01 << 6, ///< reading an explicit key (`? key`)
25  RKEY = 0x01 << 7, ///< reading a key
26  RVAL = 0x01 << 9, ///< reading a val
27  RKCL = 0x01 << 8, ///< reading the key colon (ie the : after the key in the map)
28  RNXT = 0x01 << 10, ///< read next sibling
29  SSCL = 0x01 << 11, ///< there's a stored scalar
30  QSCL = 0x01 << 12, ///< stored scalar was quoted
31  RSET = 0x01 << 13, ///< the (implicit) map being read is a !!set. @see https://yaml.org/type/set.html
32  RDOC = 0x01 << 14, ///< reading a document
33  NDOC = 0x01 << 15, ///< no document mode. a document has ended and another has not started yet.
34  USTY = 0x01 << 16, ///< reading in unknown style mode - must determine FLOW or BLCK
35  //! reading an implicit map nested in an explicit seq.
36  //! eg, {key: [key2: value2, key3: value3]}
37  //! is parsed as {key: [{key2: value2}, {key3: value3}]}
38  RSEQIMAP = 0x01 << 17,
reading unknown state (when starting): must determine whether scalar, map or seq
reading in block mode
reading in unknown style mode - must determine FLOW or BLCK reading an implicit map nested in an expl...
reading a key
ParserState_e
Enumeration of the state flags for the parser.
reading a document
reading is inside explicit flow chars: [] or {}
there's a stored scalar
reading a val
read next sibling
reading a seq
reading the key colon (ie the : after the key in the map)
reading an explicit key (? key)
reading a map
reading at top level
stored scalar was quoted
the (implicit) map being read is a !!set.
int ParserFlag_t
data type for ParserState_e
no document mode. a document has ended and another has not started yet.

Function Documentation

template<class Fn >
void c4::yml::escape_scalar_fn ( Fn &&  fn,
csubstr  scalar,
bool  keep_newlines = false 
)

Iterate through a scalar and escape special characters in it.

This function takes a callback (which accepts a single parameter of csubstr type) and, while processing, calls this callback as appropriate, passing ranges of the scalar and/or escaped characters.

Parameters
fna sink function receiving a csubstr
scalarthe scalar to be escaped
keep_newlineswhen true, \n will be escaped as \\n\n instead of just \\n

Example usage:

  • ```c++ // escape to stdout void escape_scalar(FILE *file, csubstr scalar) { auto print_ = [](csubstr repl){ fwrite(repl.len, 1, repl.str, file); }; escape_scalar_fn(std::ref(print_), scalar); }

    // escape to a different buffer and return the required buffer size size_t escape_scalar(substr buffer, csubstr scalar) { C4_ASSERT(!buffer.overlaps(scalar)); size_t pos = 0; auto _append = [&](csubstr repl){ if(repl.len && (pos + repl.len <= buffer.len)) memcpy(buffer.str + pos, repl.str, repl.len); pos += repl.len; }; escape_scalar_fn(std::ref(_append), scalar); return pos; }

  • ```

Definition at line 50 of file escape_scalar.hpp.

Referenced by dump(), and escape_scalar().

51 {
52  size_t prev = 0; // the last position that was flushed
53  size_t skip = 0; // how much to add to prev
54  csubstr repl; // replacement string
55  bool newl = false; // to add a newline
56  // cast to u8 to avoid having to deal with negative
57  // signed chars (which are present in some platforms)
58  uint8_t const* C4_RESTRICT s = reinterpret_cast<uint8_t const*>(scalar.str); // NOLINT(*-reinterpret-cast)
59  // NOLINTBEGIN(*-goto,bugprone-use-after-move,hicpp-invalid-access-moved)
60  for(size_t i = 0; i < scalar.len; ++i)
61  {
62  switch(s[i])
63  {
64  case UINT8_C(0x0a): // \n
65  repl = "\\n";
66  skip = 1;
67  if(keep_newlines)
68  newl = true;
69  goto flush_now;
70  case UINT8_C(0x5c): // '\\'
71  repl = "\\\\";
72  skip = 1;
73  goto flush_now;
74  case UINT8_C(0x09): // \t
75  repl = "\\t";
76  skip = 1;
77  goto flush_now;
78  case UINT8_C(0x0d): // \r
79  repl = "\\r";
80  skip = 1;
81  goto flush_now;
82  case UINT8_C(0x00): // \0
83  repl = "\\0";
84  skip = 1;
85  goto flush_now;
86  case UINT8_C(0x0c): // \f (form feed)
87  repl = "\\f";
88  skip = 1;
89  goto flush_now;
90  case UINT8_C(0x08): // \b (backspace)
91  repl = "\\b";
92  skip = 1;
93  goto flush_now;
94  case UINT8_C(0x07): // \a (bell)
95  repl = "\\a";
96  skip = 1;
97  goto flush_now;
98  case UINT8_C(0x0b): // \v (vertical tab)
99  repl = "\\v";
100  skip = 1;
101  goto flush_now;
102  case UINT8_C(0x1b): // \e (escape)
103  repl = "\\e";
104  skip = 1;
105  goto flush_now;
106  case UINT8_C(0xc2): // AKA -0x3e
107  if(i+1 < scalar.len)
108  {
109  if(s[i+1] == UINT8_C(0xa0)) // AKA -0x60
110  {
111  repl = "\\_";
112  skip = 2;
113  goto flush_now;
114  }
115  else if(s[i+1] == UINT8_C(0x85)) // AKA -0x7b
116  {
117  repl = "\\N";
118  skip = 2;
119  goto flush_now;
120  }
121  }
122  continue;
123  case UINT8_C(0xe2): // AKA -0x1e
124  if(i+2 < scalar.len)
125  {
126  if(s[i+1] == UINT8_C(0x80)) // AKA -0x80
127  {
128  if(s[i+2] == UINT8_C(0xa8)) // AKA -0x58
129  {
130  repl = "\\L";
131  skip = 3;
132  goto flush_now;
133  }
134  else if(s[i+2] == UINT8_C(0xa9)) // AKA -0x57
135  {
136  repl = "\\P";
137  skip = 3;
138  goto flush_now;
139  }
140  }
141  }
142  continue;
143  default:
144  continue;
145  }
146  flush_now:
147  std::forward<Fn>(fn)(scalar.range(prev, i));
148  std::forward<Fn>(fn)(repl);
149  if(newl)
150  {
151  std::forward<Fn>(fn)("\n");
152  newl = false;
153  }
154  prev = i + skip;
155  }
156  // flush the rest
157  if(scalar.len > prev)
158  std::forward<Fn>(fn)(scalar.sub(prev));
159  // NOLINTEND(*-goto,bugprone-use-after-move,hicpp-invalid-access-moved)
160 }
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
size_t c4::yml::adjust_pos_with_escapes ( csubstr  scalar,
size_t  pos,
bool  keep_newlines = false 
)
inline

Adjust a position in a scalar, increasing it to account for any escaped characters.

Note
This is a utility/debugging function, so it is provided in this optional header. For this reason, we inline it to obey to the One Definition Rule. But then we set the noinline attribute to ensure they are not inlined in calling code.

Definition at line 172 of file escape_scalar.hpp.

173 {
174  // cast to u8 to avoid having to deal with negative
175  // signed chars (which are present in some platforms)
176  uint8_t const* C4_RESTRICT s = reinterpret_cast<uint8_t const*>(scalar.str); // NOLINT(*-reinterpret-cast)
177  const size_t newbump = keep_newlines ? 2 : 1;
178  size_t ret = 0;
179  size_t excess = pos > scalar.len ? pos - scalar.len : 0;
180  pos = pos < scalar.len ? pos : scalar.len;
181  for(size_t i = 0; i < pos; ++i)
182  {
183  ++ret;
184  switch(s[i])
185  {
186  case UINT8_C(0x5c): // '\\'
187  case UINT8_C(0x09): // \t
188  case UINT8_C(0x0d): // \r
189  case UINT8_C(0x00): // \0
190  case UINT8_C(0x0c): // \f (form feed)
191  case UINT8_C(0x08): // \b (backspace)
192  case UINT8_C(0x07): // \a (bell)
193  case UINT8_C(0x0b): // \v (vertical tab)
194  case UINT8_C(0x1b): // \e (escape)
195  ++ret; // add the backslash
196  break;
197  case UINT8_C(0x0a): // \n
198  ret += newbump;
199  break;
200  case UINT8_C(0xc2): // AKA -0x3e
201  if(i+1 < scalar.len)
202  {
203  if(s[i+1] == UINT8_C(0xa0) // AKA -0x60 -> \_
204  ||
205  s[i+1] == UINT8_C(0x85)) // AKA -0x7b -> \N
206  {
207  ++ret;
208  ++i; // skip the next entry
209  }
210  }
211  break;
212  case UINT8_C(0xe2): // AKA -0x1e
213  if(i+2 < scalar.len)
214  {
215  if(s[i+1] == UINT8_C(0x80)) // AKA -0x80
216  {
217  if(s[i+2] == UINT8_C(0xa8) // AKA -0x58 -> \L
218  ||
219  s[i+2] == UINT8_C(0xa9)) // AKA -0x57 -> \P
220  {
221  ++ret;
222  i += 2; // skip the next two entries
223  }
224  }
225  }
226  break;
227  default:
228  break;
229  }
230  }
231  return ret + excess;
232 }
size_t c4::yml::escape_scalar ( substr  buffer,
csubstr  scalar,
bool  keep_newlines = false 
)
inline

Escape a scalar to an existing buffer, using escape_scalar_fn.

Note
This is a utility/debugging function, so it is provided in this optional header. For this reason, we inline it to obey to the One Definition Rule. But then we set the noinline attribute to ensure they are not inlined in calling code.

Definition at line 241 of file escape_scalar.hpp.

Referenced by c4::yml::extra::events_ints_to_testsuite(), and to_chars().

242 {
243  size_t pos = 0;
244  C4_ASSERT(!buffer.overlaps(scalar));
245  auto append_ = [&pos, &buffer](csubstr repl){
246  if(repl.len && (pos + repl.len <= buffer.len))
247  memcpy(buffer.str + pos, repl.str, repl.len);
248  pos += repl.len;
249  };
250  escape_scalar_fn(append_, scalar, keep_newlines);
251  return pos;
252 }
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
void escape_scalar_fn(Fn &&fn, csubstr scalar, bool keep_newlines=false)
Iterate through a scalar and escape special characters in it.
size_t c4::yml::to_chars ( substr  buf,
escaped_scalar  e 
)
inline

formatting implementation to escape a scalar with escape_scalar()

Definition at line 264 of file escape_scalar.hpp.

Referenced by scalar_serialize(), and to_chars_float().

265 {
266  return escape_scalar(buf, e.scalar, e.keep_newlines);
267 }
size_t escape_scalar(substr buffer, csubstr scalar, bool keep_newlines=false)
Escape a scalar to an existing buffer, using escape_scalar_fn.
template<class SinkPfn >
size_t c4::yml::dump ( SinkPfn &&  sinkfn,
substr  buf,
escaped_scalar const &  e 
)

dumping implementation to escape a scalar with escape_scalar_fn()

Definition at line 270 of file escape_scalar.hpp.

271 {
272  (void)buf;
273  C4_ASSERT(!buf.overlaps(e.scalar));
274  escape_scalar_fn(std::forward<SinkPfn>(sinkfn), e.scalar, e.keep_newlines);
275  return 0;
276 }
void escape_scalar_fn(Fn &&fn, csubstr scalar, bool keep_newlines=false)
Iterate through a scalar and escape special characters in it.
template<class K , class V , class Less , class Alloc >
void c4::yml::write ( c4::yml::Tree *  tree,
c4::yml::id_type  id,
std::map< K, V, Less, Alloc > const &  m 
)

serialize a map to a node: implementation for Tree

Definition at line 18 of file map.hpp.

19 {
20  tree->set_map(id);
21  for(auto const& C4_RESTRICT p : m)
22  {
23  id_type child = tree->append_child(id);
24  tree->set_key_serialized(child, p.first);
25  tree->set_serialized(child, p.second);
26  }
27 }
void set_map(id_type node) RYML_NOEXCEPT
Definition: tree.hpp:731
void set_key_serialized(id_type node, T const &key) RYML_NOEXCEPT
Definition: tree.hpp:837
id_type append_child(id_type parent)
create and insert a node as the last child of parent
Definition: tree.hpp:1180
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
void set_serialized(id_type node, T const &val) RYML_NOEXCEPT
Definition: tree.hpp:823
template<class K , class V , class Less , class Alloc >
void c4::yml::write ( c4::yml::NodeRef *  n,
std::map< K, V, Less, Alloc > const &  m 
)
inline

serialize a map to a node: implementation for NodeRef

Definition at line 31 of file map.hpp.

32 {
33  n->set_map();
34  for(auto const& C4_RESTRICT p : m)
35  {
36  NodeRef ch = n->append_child();
37  ch.set_key_serialized(p.first);
38  ch.set_serialized(p.second);
39  }
40 }
NodeRef append_child()
Definition: node.hpp:1715
void set_key_serialized(T const &k)
serialize a variable, then assign the result to the node's key
Definition: node.hpp:1396
void set_map()
Definition: node.hpp:1257
template<class K , class V , class Less , class Alloc >
ReadResult c4::yml::read ( c4::yml::Tree const *  tree,
c4::yml::id_type  id,
std::map< K, V, Less, Alloc > *  m 
)

deserialize a map from a node: implementation for Tree .

Read the node members, assigning into the existing map. If a key is already present in the map, then its value will be move-assigned. The map

Definition at line 48 of file map.hpp.

49 {
50  if C4_UNLIKELY(!tree->is_map(id))
51  return ReadResult(id);
52  for(id_type child = tree->first_child(id); child != NONE; child = tree->next_sibling(child))
53  {
54  K k{};
55  ReadResult result = tree->deserialize_key(child, &k);
56  if C4_UNLIKELY(!result)
57  return result;
58  result = tree->deserialize(child, &(*m)[std::move(k)]);
59  if C4_UNLIKELY(!result)
60  return result;
61  }
62  return ReadResult();
63 }
an index to none
Definition: common.hpp:131
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
template<class K , class V , class Less , class Alloc >
ReadResult c4::yml::read ( c4::yml::ConstNodeRef const &  n,
std::map< K, V, Less, Alloc > *  m 
)

deserialize a map from a node: implementation for ConstNodeRef .

read the node members, assigning into the existing map. If a key is already present in the map, then its value will be move-assigned.

Definition at line 70 of file map.hpp.

71 {
72  if C4_UNLIKELY(!n.is_map())
73  return ReadResult(n.id());
74  for(ConstNodeRef const& C4_RESTRICT ch : n)
75  {
76  K k{};
77  ReadResult result = ch.deserialize_key(&k);
78  if C4_UNLIKELY(!result)
79  return result;
80  result = ch.deserialize(&(*m)[std::move(k)]);
81  if C4_UNLIKELY(!result)
82  return result;
83  }
84  return ReadResult();
85 }
template<class T , class Alloc >
void c4::yml::write ( Tree *  tree,
id_type  id,
std::vector< T, Alloc > const &  vec 
)

serialize a vector to a node: implementation for Tree

Definition at line 19 of file vector.hpp.

20 {
21  tree->set_seq(id);
22  for(T const& val : vec)
23  tree->set_serialized(tree->append_child(id), val);
24 }
template<class T , class Alloc >
void c4::yml::write ( NodeRef *  n,
std::vector< T, Alloc > const &  vec 
)

serialize a vector to a node: implementation for NodeRef

Definition at line 28 of file vector.hpp.

29 {
30  // don't defer to the tree impl here (if that were the case, we
31  // wouldn't even need to implement this function, as ryml ends up
32  // calling the tree impl by default). It may be the case that the
33  // serialization of T uses a serialization of a nested type that
34  // is not available in the tree implementation, so we need to
35  // provide this as a hook for that. If that's not required, then
36  // the tree implementation will get called anyway.
37  n->set_seq();
38  for(T const& val : vec)
39  {
40  NodeRef ch = n->append_child();
41  // call write() directly. ch.set_serialized() would also work,
42  // but does an additional check (to create the node if it is a
43  // seed). That check is not needed here because we used
44  // .append_child() to create the node.
45  write(&ch, val);
46  }
47 }
void write(NodeRef *n, std::vector< T, Alloc > const &vec)
serialize a vector to a node: implementation for NodeRef
Definition: vector.hpp:28
template<class T , class Alloc >
ReadResult c4::yml::read ( Tree const *  tree,
id_type  id,
std::vector< T, Alloc > *  vec 
)

deserialize from a Tree node, overwriting existing vector entries.

Definition at line 52 of file vector.hpp.

53 {
54  if C4_UNLIKELY(!tree->is_seq(id))
55  return ReadResult(id);
56  vec->clear();
57  #if C4_CPP < 17 // prior to C++17, emplace_back() does not return a reference
58  size_t pos = 0;
59  #endif
60  for(id_type child = tree->first_child(id); child != NONE; child = tree->next_sibling(child))
61  {
62  #if C4_CPP >= 17
63  T &val = vec->emplace_back();
64  #else
65  vec->emplace_back();
66  T &val = (*vec)[pos++];
67  #endif
68  // do not call read(tree, child, &val) here. we do not know
69  // that the YAML is valid, so we need to do the checks in
70  // child.deserialize()
71  if(!tree->deserialize(child, &val))
72  return ReadResult(id);
73  }
74  return ReadResult{};
75 }
an index to none
Definition: common.hpp:131
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
template<class T , class Alloc >
ReadResult c4::yml::read ( ConstNodeRef const &  node,
std::vector< T, Alloc > *  vec 
)

deserialize from a ConstNodeRef node, overwriting existing vector entries.

Definition at line 79 of file vector.hpp.

80 {
81  // don't defer to the tree impl here (if that were the case, we
82  // wouldn't even need to implement this function, as ryml ends up
83  // calling the tree impl by default). It may be the case that the
84  // serialization of T uses a serialization of a nested type that
85  // is not available in the tree implementation, so we need to
86  // provide this as a hook for that. If that's not required, then
87  // the tree implementation will get called anyway.
88  if C4_UNLIKELY(!node.is_seq())
89  return ReadResult(node.id());
90  vec->clear();
91  #if C4_CPP < 17 // prior to C++17, emplace_back() does not return a reference
92  size_t pos = 0;
93  #endif
94  for(ConstNodeRef const& child : node.children())
95  {
96  #if C4_CPP >= 17
97  T &val = vec->emplace_back();
98  #else
99  vec->emplace_back();
100  T &val = (*vec)[pos++];
101  #endif
102  // do not call read(child, &val) here. we do not know that the
103  // YAML is valid, so we need to do the checks in
104  // child.deserialize()
105  if(!child.deserialize(&val))
106  return ReadResult(child.id());
107  }
108  return ReadResult();
109 }
template<class Alloc >
ReadResult c4::yml::read ( Tree const *  tree,
id_type  id,
std::vector< bool, Alloc > *  vec 
)

deserialize from a Tree node, overwriting existing vector entries.

Definition at line 119 of file vector.hpp.

120 {
121  if C4_UNLIKELY(!tree->is_seq(id))
122  return ReadResult(id);
123  vec->clear();
124  bool tmp = {};
125  for(id_type child = tree->first_child(id); child != NONE; child = tree->next_sibling(child))
126  {
127  if(!from_chars(tree->val(child), &tmp))
128  return ReadResult(child);
129  vec->push_back(tmp); // leave this. gcc4.8 does not have std::vector<bool>::emplace_back()
130  }
131  return ReadResult();
132 }
an index to none
Definition: common.hpp:131
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
bool from_chars(c4::csubstr buf, std::vector< char, Alloc > *s)
copy a csubstr to an existing std::vector
Definition: vector.hpp:84
template<class Alloc >
ReadResult c4::yml::read ( ConstNodeRef const &  n,
std::vector< bool, Alloc > *  vec 
)

deserialize from a ConstNodeRef node, overwriting existing vector entries.

Definition at line 136 of file vector.hpp.

137 {
138  // call the tree implementation, saving the node readability
139  // checks. we can do that here because bool (the value type) is a
140  // final type, so it can't be overrided.
141  return read(n.tree(), n.id(), vec);
142 }
ReadResult read(ConstNodeRef const &n, std::vector< bool, Alloc > *vec)
deserialize from a ConstNodeRef node, overwriting existing vector entries.
Definition: vector.hpp:136
csubstr c4::yml::version ( )

Definition at line 6 of file version.cpp.

7 {
8  return RYML_VERSION;
9 }
#define RYML_VERSION
Definition: version.hpp:6
int c4::yml::version_major ( )

Definition at line 11 of file version.cpp.

12 {
13  return RYML_VERSION_MAJOR;
14 }
#define RYML_VERSION_MAJOR
Definition: version.hpp:7
int c4::yml::version_minor ( )

Definition at line 16 of file version.cpp.

17 {
18  return RYML_VERSION_MINOR;
19 }
#define RYML_VERSION_MINOR
Definition: version.hpp:8
int c4::yml::version_patch ( )

Definition at line 21 of file version.cpp.

22 {
23  return RYML_VERSION_PATCH;
24 }
#define RYML_VERSION_PATCH
Definition: version.hpp:9