rapidyaml  0.13.0
parse and emit YAML, and do it fast
c4::yml Namespace Reference

Namespaces

 detail
 a CRTP base providing read-only methods for ConstNodeRef and NodeRef
 
 extra
 

Classes

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  ErrorDataBasic
 Data for a basic error. More...
 
struct  ErrorDataParse
 Data for a parse error. More...
 
struct  ErrorDataVisit
 Data for a visit error. More...
 
struct  ParserOptions
 Options to give to the parser to control its behavior. More...
 
struct  Callbacks
 A c-style callbacks class to customize behavior on errors or allocation. More...
 
class  Emitter
 A stateful emitter, for use with a writer such as WriterBuf, WriterFile, or WriterOStream. More...
 
struct  EmitOptions
 A lightweight object containing options to be used when emitting. More...
 
struct  as_json
 mark a tree or node to be emitted as yaml when using operator<<, with options. More...
 
struct  as_yaml
 mark a tree or node to be emitted as yaml when using operator<< . 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  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  FilterResult
 Abstracts the fact that a scalar filter result may not fit in the intended memory. More...
 
struct  FilterResultExtending
 Abstracts the fact that a scalar filter result may not fit in the intended memory. More...
 
struct  FilterProcessorSrcDst
 Filters an input string into a different output string. More...
 
struct  FilterProcessorInplaceEndExtending
 Filters in place. More...
 
struct  FilterProcessorInplaceMidExtending
 Filters in place. 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  Key
 
struct  Key< fmt::const_base64_wrapper >
 
struct  Key< fmt::base64_wrapper >
 
class  ConstNodeRef
 Holds a pointer to an existing tree, and a node id. 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  NodeType
 wraps a NodeType_e element with some syntactic sugar and predicates More...
 
struct  LineContents
 Helper to control the line contents while parsing a buffer. More...
 
struct  ParserState
 
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
 
struct  NodeScalar
 a node scalar is a csubstr, which may be tagged and anchored. More...
 
struct  NodeInit
 convenience class to initialize nodes More...
 
struct  NodeData
 contains the data for each YAML node. More...
 
class  Tree
 
struct  WriterFile
 A writer that outputs to a file. More...
 
struct  WriterOStream
 A writer that outputs to an STL-like ostream. More...
 
struct  WriterBuf
 a writer to a substr 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...
 
template<class OStream >
using EmitterOStream = Emitter< WriterOStream< OStream > >
 
using EmitterFile = Emitter< WriterFile >
 
using EmitterBuf = Emitter< WriterBuf >
 
using Parser = ParseEngine< EventHandlerTree >
 This is the main ryml parser, where the parser events are handled to create a ryml tree. 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  EmitType_e { EMIT_YAML = 0 , EMIT_JSON = 1 }
 Specifies the type of content to emit. More...
 
enum  NodeType_e : type_bits {
  NOTYPE = 0 , KEY = __(0) , VAL = __(1) , MAP = __(2) ,
  SEQ = __(3) , DOC = __(4) , STREAM = __(5)|SEQ , KEYREF = __(6) ,
  VALREF = __(7) , KEYANCH = __(8) , VALANCH = __(9) , KEYTAG = __(10) ,
  VALTAG = __(11) , KEYNIL = __(12) , VALNIL = __(13) , _TYMASK = __(14)-1 ,
  KEY_UNFILT = __(14) , VAL_UNFILT = __(15) , FLOW_SL = __(16) , FLOW_ML = __(17) ,
  BLOCK = __(18) , KEY_LITERAL = __(19) , VAL_LITERAL = __(20) , KEY_FOLDED = __(21) ,
  VAL_FOLDED = __(22) , KEY_SQUO = __(23) , VAL_SQUO = __(24) , KEY_DQUO = __(25) ,
  VAL_DQUO = __(26) , KEY_PLAIN = __(27) , VAL_PLAIN = __(28) , 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 = KEY_LITERAL|KEY_FOLDED|KEY_SQUO|KEY_DQUO|KEY_PLAIN , VAL_STYLE = VAL_LITERAL|VAL_FOLDED|VAL_SQUO|VAL_DQUO|VAL_PLAIN , SCALAR_STYLE = KEY_STYLE|VAL_STYLE , CONTAINER_STYLE_FLOW = FLOW_SL|FLOW_ML ,
  CONTAINER_STYLE_BLOCK = BLOCK , CONTAINER_STYLE = FLOW_SL|FLOW_ML|BLOCK , STYLE = SCALAR_STYLE | CONTAINER_STYLE , _KEYMASK = KEY | KEYQUO | KEYANCH | KEYREF | KEYTAG ,
  _VALMASK = VAL | VALQUO | VALANCH | VALREF | VALTAG
}
 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...
 
size_t 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...
 
size_t emit_yaml (Tree const &t, id_type id, FILE *f)
 (2) like (1), but use default emit options More...
 
size_t 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...
 
size_t emit_json (Tree const &t, id_type id, FILE *f)
 (2) like (1), but use default emit options More...
 
size_t emit_yaml (Tree const &t, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit YAML to the given file, starting at the root node. More...
 
size_t emit_yaml (Tree const &t, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
size_t emit_json (Tree const &t, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit JSON to the given file. More...
 
size_t emit_json (Tree const &t, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
size_t emit_yaml (ConstNodeRef const &r, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit YAML to the given file. More...
 
size_t emit_yaml (ConstNodeRef const &r, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
size_t emit_json (ConstNodeRef const &r, EmitOptions const &opts, FILE *f=nullptr)
 (1) emit JSON to the given file. More...
 
size_t emit_json (ConstNodeRef const &r, FILE *f=nullptr)
 (2) like (1), but use default emit options More...
 
template<class OStream >
OStream & operator<< (OStream &s, Tree const &t)
 emit YAML to an STL-like ostream More...
 
template<class OStream >
OStream & operator<< (OStream &s, ConstNodeRef const &n)
 emit YAML to an STL-like ostream This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
template<class OStream >
OStream & operator<< (OStream &s, as_json const &j)
 emit json to an STL-like stream More...
 
template<class OStream >
OStream & operator<< (OStream &s, as_yaml const &y)
 emit yaml to an STL-like stream 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 (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 (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-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-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-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-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-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-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-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-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-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-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-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-like container. 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...
 
template<class K >
Key< K > key (K &k)
 
Key< fmt::const_base64_wrapperkey (fmt::const_base64_wrapper w)
 
Key< fmt::base64_wrapperkey (fmt::base64_wrapper w)
 
template<class T >
void write (NodeRef *n, T const &v)
 
template<class T >
bool read (ConstNodeRef const &n, T *v)
 
template<class T >
bool read (NodeRef const &n, T *v)
 
template<class T >
bool readkey (ConstNodeRef const &n, T *v)
 
template<class T >
bool readkey (NodeRef const &n, T *v)
 
constexpr C4_CONST NodeType_e operator| (NodeType_e lhs, NodeType_e rhs) noexcept
 
constexpr C4_CONST NodeType_e operator& (NodeType_e lhs, NodeType_e rhs) noexcept
 
constexpr C4_CONST NodeType_e operator>> (NodeType_e bits, uint32_t n) noexcept
 
constexpr C4_CONST NodeType_e operator<< (NodeType_e bits, uint32_t n) noexcept
 
constexpr C4_CONST NodeType_e operator~ (NodeType_e bits) noexcept
 
NodeType_eoperator&= (NodeType_e &subject, NodeType_e bits) noexcept
 
NodeType_eoperator|= (NodeType_e &subject, NodeType_e bits) noexcept
 
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_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_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, 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...
 
size_t preprocess_rxmap (csubstr rxmap, substr buf)
 Write into a given output buffer. More...
 
template<class CharContainer >
substr preprocess_rxmap (csubstr rxmap, CharContainer *out)
 
template<class CharContainer >
CharContainer preprocess_rxmap (csubstr rxmap)
 
template<class K , class V , class Less , class Alloc >
void write (c4::yml::NodeRef *n, std::map< K, V, Less, Alloc > const &m)
 
template<class K , class V , class Less , class Alloc >
bool read (c4::yml::ConstNodeRef const &n, std::map< K, V, Less, Alloc > *m)
 read the node members, assigning into the existing map. More...
 
template<class V , class Alloc >
void write (c4::yml::NodeRef *n, std::vector< V, Alloc > const &vec)
 
template<class V , class Alloc >
bool read (c4::yml::ConstNodeRef const &n, std::vector< V, Alloc > *vec)
 read the node members, overwriting existing vector entries. More...
 
template<class Alloc >
bool read (c4::yml::ConstNodeRef const &n, std::vector< bool, Alloc > *vec)
 read the node members, 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 (Tree *tree, csubstr a)
 
template<class T >
size_t to_chars_float (substr buf, T val)
 encode a floating point value to a string. More...
 
template<class T >
bool from_chars_float (csubstr buf, T *val)
 decode a floating point from string. More...
 
template<class T >
auto serialize_scalar (substr buf, T const &a) -> typename std::enable_if< std::is_floating_point< T >::value, size_t >::type
 
template<class T >
csubstr serialize_to_arena (Tree *tree, T const &a)
 
csubstr serialize_to_arena (Tree *tree, substr a)
 
csubstr serialize_to_arena (Tree *tree, const char *a)
 
csubstr serialize_to_arena (Tree *, std::nullptr_t)
 
template<class T >
auto read (Tree const *tree, id_type id, T *v) -> typename std::enable_if<!std::is_arithmetic< T >::value, bool >::type
 convert the val of a scalar node to a particular non-arithmetic non-float type, by forwarding its val to from_chars<T>(). More...
 
template<class T >
auto readkey (Tree const *tree, id_type id, T *v) -> typename std::enable_if<!std::is_arithmetic< T >::value, bool >::type
 convert the key of a node to a particular non-arithmetic non-float type, by forwarding its key to from_chars<T>(). More...
 
template<class T >
std::enable_if< std::is_floating_point< T >::value, bool >::type read (Tree const *tree, id_type id, T *v)
 convert the val of a scalar node to a floating point type, by forwarding its val to from_chars_float<T>(). More...
 
template<class T >
std::enable_if< std::is_floating_point< T >::value, bool >::type readkey (Tree const *tree, id_type id, T *v)
 convert the key of a scalar node to a floating point type, by forwarding its key to from_chars_float<T>(). More...
 
csubstr version ()
 
int version_major ()
 
int version_minor ()
 
int version_patch ()
 
scalar style helpers
bool scalar_style_query_squo (csubstr s) noexcept
 query whether a scalar can be encoded using single quotes. More...
 
bool scalar_style_query_plain_flow (csubstr s) noexcept
 query whether a scalar can be encoded using plain style while in flow mode. More...
 
bool scalar_style_query_plain_block (csubstr s) noexcept
 query whether a scalar can be encoded using plain style while in block mode. More...
 
NodeType_e scalar_style_choose_flow (csubstr scalar) noexcept
 choose a YAML scalar style based on the scalar's contents, while in flow mode. More...
 
NodeType_e scalar_style_choose_block (csubstr scalar) noexcept
 choose a YAML scalar style based on the scalar's contents, while in block mode. More...
 
bool scalar_is_null (csubstr s) noexcept
 YAML-sense query of nullity. More...
 
NodeType_e scalar_style_choose_json (csubstr scalar) noexcept
 choose a json scalar style based on the scalar's contents More...
 
NodeType_e scalar_style_choose (csubstr s, bool flow=true) noexcept
 choose a YAML emitting style based on the scalar's contents. More...
 
bool scalar_style_query_plain (csubstr s, bool flow=true) noexcept
 query whether a scalar can be encoded using plain style. More...
 

Typedef Documentation

◆ id_type

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 244 of file common.hpp.

◆ Encoding_e

◆ ParserFlag_t

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

anonymous enum : id_type
Enumerator
NONE 

an index to none

Definition at line 249 of file common.hpp.

249  : id_type { // NOLINT
250  /** an index to none */
251  NONE = id_type(-1), // NOLINT
252 };
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:244
@ NONE
an index to none
Definition: common.hpp:251

◆ anonymous enum

anonymous enum : size_t
Enumerator
npos 

a null string position

Definition at line 256 of file common.hpp.

256  : size_t { // NOLINT
257  /** a null string position */
258  npos = size_t(-1) // NOLINT
259 };
@ npos
a null string position
Definition: common.hpp:258

◆ Encoding_

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 262 of file common.hpp.

262  { // NOLINT
263  NOBOM, //!< No Byte Order Mark was found
264  UTF8, //!< UTF8
265  UTF16LE, //!< UTF16, Little-Endian
266  UTF16BE, //!< UTF16, Big-Endian
267  UTF32LE, //!< UTF32, Little-Endian
268  UTF32BE, //!< UTF32, Big-Endian
269 } Encoding_e;
@ UTF16BE
UTF16, Big-Endian.
Definition: common.hpp:266
@ UTF8
UTF8.
Definition: common.hpp:264
@ UTF16LE
UTF16, Little-Endian.
Definition: common.hpp:265
@ NOBOM
No Byte Order Mark was found.
Definition: common.hpp:263
@ UTF32BE
UTF32, Big-Endian.
Definition: common.hpp:268
@ UTF32LE
UTF32, Little-Endian.
Definition: common.hpp:267
enum c4::yml::Encoding_ Encoding_e

◆ ParserState_e

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,
ParserState_e
Enumeration of the state flags for the parser.
@ RTOP
reading at top level
@ RSET
the (implicit) map being read is a !!set.
@ RSEQ
reading a seq
@ RNXT
read next sibling
@ RUNK
reading unknown state (when starting): must determine whether scalar, map or seq
@ RKEY
reading a key
@ RKCL
reading the key colon (ie the : after the key in the map)
@ NDOC
no document mode. a document has ended and another has not started yet.
@ RDOC
reading a document
@ QSCL
stored scalar was quoted
@ RBLCK
reading in block mode
@ RMAP
reading a map
@ USTY
reading in unknown style mode - must determine FLOW or BLCK reading an implicit map nested in an expl...
@ QMRK
reading an explicit key (? key)
@ SSCL
there's a stored scalar
@ RVAL
reading a val
@ RFLOW
reading is inside explicit flow chars: [] or {}
int ParserFlag_t
data type for ParserState_e

Function Documentation

◆ escape_scalar_fn()

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;
}
size_t escape_scalar(substr buffer, csubstr scalar, bool keep_newlines=false)
Escape a scalar to an existing buffer, using escape_scalar_fn.
void escape_scalar_fn(Fn &&fn, csubstr scalar, bool keep_newlines=false)
Iterate through a scalar and escape special characters in it.

Definition at line 50 of file escape_scalar.hpp.

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 }

◆ adjust_pos_with_escapes()

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 }

◆ escape_scalar()

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.

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 }

◆ to_chars()

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.

265 {
266  return escape_scalar(buf, e.scalar, e.keep_newlines);
267 }

◆ dump()

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 }

◆ write() [1/2]

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 
)

Definition at line 17 of file map.hpp.

18 {
19  *n |= c4::yml::MAP;
20  for(auto const& C4_RESTRICT p : m)
21  {
22  auto ch = n->append_child();
23  ch << c4::yml::key(p.first);
24  ch << p.second;
25  }
26 }
NodeRef append_child()
Definition: node.hpp:1414
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:39
Key< K > key(K &k)
Definition: node.hpp:46

◆ read() [1/4]

template<class K , class V , class Less , class Alloc >
bool c4::yml::read ( c4::yml::ConstNodeRef const &  n,
std::map< K, V, Less, Alloc > *  m 
)

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 32 of file map.hpp.

33 {
34  for(auto const& C4_RESTRICT ch : n)
35  {
36  K k{};
37  ch >> c4::yml::key(k);
38  ch >> (*m)[k];
39  }
40  return true;
41 }

◆ write() [2/2]

template<class V , class Alloc >
void c4::yml::write ( c4::yml::NodeRef n,
std::vector< V, Alloc > const &  vec 
)

Definition at line 17 of file vector.hpp.

18 {
19  *n |= c4::yml::SEQ;
20  for(V const& v : vec)
21  n->append_child() << v;
22 }
@ SEQ
a seq: a parent of VAL/SEQ/MAP nodes
Definition: node_type.hpp:40

◆ read() [2/4]

template<class V , class Alloc >
bool c4::yml::read ( c4::yml::ConstNodeRef const &  n,
std::vector< V, Alloc > *  vec 
)

read the node members, overwriting existing vector entries.

Definition at line 26 of file vector.hpp.

27 {
28  C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
29  vec->resize(static_cast<size_t>(n.num_children()));
30  C4_SUPPRESS_WARNING_GCC_POP
31  size_t pos = 0;
32  for(ConstNodeRef const child : n)
33  child >> (*vec)[pos++];
34  return true;
35 }

◆ read() [3/4]

template<class Alloc >
bool c4::yml::read ( c4::yml::ConstNodeRef const &  n,
std::vector< bool, Alloc > *  vec 
)

read the node members, overwriting existing vector entries.

specialization: std::vector<bool> uses std::vector<bool>::reference as the return value of its operator[].

Definition at line 41 of file vector.hpp.

42 {
43  C4_SUPPRESS_WARNING_GCC_WITH_PUSH("-Wuseless-cast")
44  vec->resize(static_cast<size_t>(n.num_children()));
45  C4_SUPPRESS_WARNING_GCC_POP
46  size_t pos = 0;
47  bool tmp = {};
48  for(ConstNodeRef const child : n)
49  {
50  child >> tmp;
51  (*vec)[pos++] = tmp;
52  }
53  return true;
54 }

◆ serialize_to_arena() [1/4]

csubstr c4::yml::serialize_to_arena ( Tree tree,
csubstr  a 
)

Definition at line 19 of file tree.cpp.

20 {
21  if(a.len > 0)
22  {
23  substr rem(tree->m_arena.sub(tree->m_arena_pos));
24  size_t num = to_chars(rem, a);
25  if(num > rem.len)
26  {
27  rem = tree->_grow_arena(num);
28  num = to_chars(rem, a);
29  _RYML_ASSERT_VISIT_(tree->m_callbacks, num <= rem.len, tree, NONE);
30  }
31  return tree->_request_span(num);
32  }
33  else
34  {
35  if(a.str == nullptr)
36  {
37  return csubstr{};
38  }
39  else if(tree->m_arena.str == nullptr)
40  {
41  // Arena is empty and we want to store a non-null
42  // zero-length string.
43  // Even though the string has zero length, we need
44  // some "memory" to store a non-nullptr string
45  tree->_grow_arena(1);
46  }
47  return tree->_request_span(0);
48  }
49 }
size_t to_chars(substr buf, escaped_scalar e)
formatting implementation to escape a scalar with escape_scalar()

◆ serialize_scalar()

template<class T >
auto c4::yml::serialize_scalar ( substr  buf,
T const &  a 
) -> typename std::enable_if<std::is_floating_point<T>::value, size_t>::type
inline

Definition at line 64 of file tree.hpp.

66 {
67  return to_chars_float(buf, a);
68 }
size_t to_chars_float(substr buf, T val)
encode a floating point value to a string.
Definition: tree.hpp:1442

◆ serialize_to_arena() [2/4]

csubstr c4::yml::serialize_to_arena ( Tree tree,
substr  a 
)
inline

Definition at line 84 of file tree.hpp.

85 {
86  return serialize_to_arena(tree, csubstr(a));
87 }
csubstr serialize_to_arena(Tree *, std::nullptr_t)
Definition: tree.hpp:92

◆ serialize_to_arena() [3/4]

csubstr c4::yml::serialize_to_arena ( Tree tree,
const char *  a 
)
inline

Definition at line 88 of file tree.hpp.

89 {
90  return serialize_to_arena(tree, to_csubstr(a));
91 }
csubstr to_csubstr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2204

◆ serialize_to_arena() [4/4]

csubstr c4::yml::serialize_to_arena ( Tree ,
std::nullptr_t   
)
inline

Definition at line 92 of file tree.hpp.

93 {
94  return csubstr{};
95 }

◆ read() [4/4]

template<class T >
std::enable_if<std::is_floating_point<T>::value, bool>::type c4::yml::read ( Tree const *  tree,
id_type  id,
T *  v 
)
inline

convert the val of a scalar node to a floating point type, by forwarding its val to from_chars_float<T>().

Returns
false if the conversion failed
Warning
Unlike non-floating types, only the leading part of the string that may constitute a number is processed. This happens because the float parsing is delegated to fast_float, which is implemented that way. Consequently, for example, all of "34", "34 " "34hg" "34 gh" will be read as 34. If you are not sure about the contents of the data, you can use csubstr::first_real_span() to check before calling >>, for example like this:
csubstr val = node.val();
if(val.first_real_span() == val)
node >> v;
else
ERROR("not a real")

Definition at line 1516 of file tree.hpp.

1517 {
1518  csubstr val = tree->val(id);
1519  return C4_LIKELY(!val.empty()) ? from_chars_float(val, v) : false;
1520 }
bool from_chars_float(csubstr buf, T *val)
decode a floating point from string.
Definition: tree.hpp:1460

◆ readkey()

template<class T >
std::enable_if<std::is_floating_point<T>::value, bool>::type c4::yml::readkey ( Tree const *  tree,
id_type  id,
T *  v 
)
inline

convert the key of a scalar node to a floating point type, by forwarding its key to from_chars_float<T>().

Returns
false if the conversion failed
Warning
Unlike non-floating types, only the leading part of the string that may constitute a number is processed. This happens because the float parsing is delegated to fast_float, which is implemented that way. Consequently, for example, all of "34", "34 " "34hg" "34 gh" will be read as 34. If you are not sure about the contents of the data, you can use csubstr::first_real_span() to check before calling >>, for example like this:
csubstr key = node.key();
if(key.first_real_span() == key)
node >> v;
else
ERROR("not a real")

Definition at line 1546 of file tree.hpp.

1547 {
1548  csubstr key = tree->key(id);
1549  return C4_LIKELY(!key.empty()) ? from_chars_float(key, v) : false;
1550 }

◆ version()

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

◆ version_major()

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

◆ version_minor()

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

◆ version_patch()

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