rapidyaml  0.7.1
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
 

Classes

struct  LineCol
 holds a position into a source buffer More...
 
struct  Location
 a source file position More...
 
struct  Callbacks
 a c-style callbacks class. 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  EventHandlerStack
 Use this class a base of implementations of event handler to simplify the stack logic. More...
 
struct  EventHandlerTreeState
 The stack state needed specifically by EventHandlerTree. More...
 
struct  EventHandlerTree
 The event handler to create a ryml Tree. 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  ParserOptions
 Options to give to the parser to control its behavior. 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 the tree. More...
 
struct  TagDirective
 
struct  TagDirectiveRange
 
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...
 
struct  EventHandlerYamlStdState
 The stack state needed specifically by EventHandlerYamlStd. More...
 
struct  EventHandlerYamlStd
 The event handler producing standard YAML events as used in the YAML test suite. 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...
 
using pfn_error = void(*)(const char *msg, size_t msg_len, Location location, void *user_data)
 the type of the function used to report errors More...
 
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...
 
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  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) , _TYMASK = __(12)-1 , KEY_UNFILT = __(12) , VAL_UNFILT = __(13) ,
  FLOW_SL = __(14) , FLOW_ML = __(15) , BLOCK = __(16) , KEY_LITERAL = __(17) ,
  VAL_LITERAL = __(18) , KEY_FOLDED = __(19) , VAL_FOLDED = __(20) , KEY_SQUO = __(21) ,
  VAL_SQUO = __(22) , KEY_DQUO = __(23) , VAL_DQUO = __(24) , KEY_PLAIN = __(25) ,
  VAL_PLAIN = __(26) , 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 ,
  FLOW = 0x01 << 4 , BLCK = 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 report_error_impl (const char *msg, size_t length, Location loc, FILE *f)
 
void error_impl (const char *msg, size_t length, Location loc, void *)
 
void * allocate_impl (size_t length, void *, void *)
 
void free_impl (void *mem, size_t, void *)
 
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 error (Callbacks const &cb, const char *msg, size_t msg_len, Location loc)
 
void error (const char *msg, size_t msg_len, Location loc)
 
bool _is_indented_block (csubstr s, size_t prev, size_t i) noexcept
 
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 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 >
std::enable_if< ! std::is_floating_point< T >::value, bool >::type read (NodeRef const &n, 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 read (NodeRef const &n, 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 >
auto read (NodeRef const &n, T *v) -> typename std::enable_if< ! std::is_floating_point< T >::value, bool >::type
 convert the val of a scalar node to a particular type, by forwarding its val to from_chars<T>(). More...
 
template<class T >
auto read (ConstNodeRef const &n, T *v) -> typename std::enable_if< ! std::is_floating_point< T >::value, bool >::type
 convert the val of a scalar node to a particular type, by forwarding its val to from_chars<T>(). More...
 
template<class T >
std::enable_if< std::is_floating_point< T >::value, bool >::type read (ConstNodeRef const &n, T *v)
 convert the val of a scalar node to a floating point type, by forwarding its val to from_chars_float<T>(). More...
 
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 an existing tree, into its root node. 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)
 (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)
 (2) like (1) but no filename will be reported More...
 
void parse_in_place (csubstr filename, substr yaml, Tree *t)
 (3) parse YAML into an existing tree, into its root node. More...
 
void parse_in_place (substr yaml, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_in_place (csubstr filename, substr yaml, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_in_place (substr yaml, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_in_place (csubstr filename, substr yaml)
 (7) create a new tree, and parse YAML into its root node. More...
 
Tree parse_in_place (substr yaml)
 (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)
 (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)
 (2) like (1) but no filename will be reported More...
 
void parse_json_in_place (csubstr filename, substr json, Tree *t)
 (3) parse JSON into an existing tree, into its root node. More...
 
void parse_json_in_place (substr json, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_json_in_place (csubstr filename, substr json, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_json_in_place (substr json, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_json_in_place (csubstr filename, substr json)
 (7) create a new tree, and parse JSON into its root node. More...
 
Tree parse_json_in_place (substr json)
 (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)
 (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)
 (2) like (1) but no filename will be reported More...
 
void parse_in_arena (csubstr filename, csubstr yaml, Tree *t)
 (3) parse YAML into an existing tree, into its root node. More...
 
void parse_in_arena (csubstr yaml, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_in_arena (csubstr filename, csubstr yaml, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_in_arena (csubstr yaml, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_in_arena (csubstr filename, csubstr yaml)
 (7) create a new tree, and parse YAML into its root node. More...
 
Tree parse_in_arena (csubstr yaml)
 (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)
 (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)
 (2) like (1) but no filename will be reported More...
 
void parse_json_in_arena (csubstr filename, csubstr json, Tree *t)
 (3) parse JSON into an existing tree, into its root node. More...
 
void parse_json_in_arena (csubstr json, Tree *t)
 (4) like (3) but no filename will be reported More...
 
void parse_json_in_arena (csubstr filename, csubstr json, NodeRef node)
 (5) like (1) but the node is given as a NodeRef More...
 
void parse_json_in_arena (csubstr json, NodeRef node)
 (6) like (5) but no filename will be reported More...
 
Tree parse_json_in_arena (csubstr filename, csubstr json)
 (7) create a new tree, and parse JSON into its root node. More...
 
Tree parse_json_in_arena (csubstr json)
 (8) like (7) but no filename will be reported More...
 
size_t _find_last_newline_and_larger_indentation (csubstr s, size_t indentation) noexcept
 
id_type estimate_tree_capacity (csubstr src)
 Quickly inspect the source to estimate the number of nodes the resulting tree is likely 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)
 
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)
 
template<class Alloc >
bool read (c4::yml::ConstNodeRef const &n, std::vector< bool, Alloc > *vec)
 specialization: std::vector<bool> uses std::vector<bool>::reference as the return value of its operator[]. More...
 
bool is_custom_tag (csubstr tag)
 
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)
 
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...
 
void append_escaped (extra::string *s, csubstr val)
 
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 (csubstr s) noexcept
 query whether a scalar can be encoded using plain style (no quotes, not a literal/folded block scalar). More...
 
NodeType_e scalar_style_choose (csubstr scalar) noexcept
 choose a YAML emitting style based on the scalar's contents More...
 
NodeType_e scalar_style_json_choose (csubstr scalar) noexcept
 choose a json style based on the scalar's contents More...
 
bool scalar_is_null (csubstr s) noexcept
 YAML-sense query of nullity. 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 252 of file common.hpp.

◆ ParserFlag_t

using c4::yml::ParserFlag_t = typedef int

data type for ParserState_e

Definition at line 12 of file parser_state.hpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : id_type
Enumerator
NONE 

an index to none

Definition at line 257 of file common.hpp.

257  : id_type {
258  /** an index to none */
259  NONE = id_type(-1),
260 };
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:252
@ NONE
an index to none
Definition: common.hpp:259

◆ anonymous enum

anonymous enum : size_t
Enumerator
npos 

a null string position

Definition at line 264 of file common.hpp.

264  : size_t {
265  /** a null string position */
266  npos = size_t(-1)
267 };
@ npos
a null string position
Definition: common.hpp:266

◆ 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

FLOW 

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

BLCK 

reading in block mode

QMRK 

reading an explicit key (? key)

RKEY 

reading a scalar as key

RVAL 

reading a scalar as val

RKCL 

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

RNXT 

read next val or keyval

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 15 of file parser_state.hpp.

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

Function Documentation

◆ report_error_impl()

void c4::yml::report_error_impl ( const char *  msg,
size_t  length,
Location  loc,
FILE *  f 
)

Definition at line 23 of file common.cpp.

24 {
25  if(!f)
26  f = stderr;
27  if(loc)
28  {
29  if(!loc.name.empty())
30  {
31  // this is more portable than using fprintf("%.*s:") which
32  // is not available in some embedded platforms
33  fwrite(loc.name.str, 1, loc.name.len, f);
34  fputc(':', f);
35  }
36  fprintf(f, "%zu:", loc.line);
37  if(loc.col)
38  fprintf(f, "%zu:", loc.col);
39  if(loc.offset)
40  fprintf(f, " (%zuB):", loc.offset);
41  fputc(' ', f);
42  }
43  RYML_ASSERT(!csubstr(msg, length).ends_with('\0'));
44  fwrite(msg, 1, length, f);
45  fputc('\n', f);
46  fflush(f);
47 }

References c4::yml::Location::col, c4::yml::Location::line, c4::yml::Location::name, and c4::yml::Location::offset.

Referenced by error_impl().

◆ error_impl()

void c4::yml::error_impl ( const char *  msg,
size_t  length,
Location  loc,
void *   
)

Definition at line 49 of file common.cpp.

50 {
51  RYML_ASSERT(!csubstr(msg, length).ends_with('\0'));
52  report_error_impl(msg, length, loc, nullptr);
53 #ifdef RYML_DEFAULT_CALLBACK_USES_EXCEPTIONS
54  throw std::runtime_error(std::string(msg, length));
55 #else
56  ::abort();
57 #endif
58 }
void report_error_impl(const char *msg, size_t length, Location loc, FILE *f)
Definition: common.cpp:23

References report_error_impl().

Referenced by allocate_impl().

◆ allocate_impl()

void* c4::yml::allocate_impl ( size_t  length,
void *  ,
void *   
)

Definition at line 60 of file common.cpp.

61 {
62  void *mem = ::malloc(length);
63  if(mem == nullptr)
64  {
65  const char msg[] = "could not allocate memory";
66  error_impl(msg, sizeof(msg)-1, {}, nullptr);
67  }
68  return mem;
69 }
void error_impl(const char *msg, size_t length, Location loc, void *)
Definition: common.cpp:49

References error_impl().

◆ free_impl()

void c4::yml::free_impl ( void *  mem,
size_t  ,
void *   
)

Definition at line 71 of file common.cpp.

72 {
73  ::free(mem);
74 }

◆ error() [1/2]

void c4::yml::error ( Callbacks const &  cb,
const char *  msg,
size_t  msg_len,
Location  loc 
)

Definition at line 130 of file common.cpp.

131 {
132  cb.m_error(msg, msg_len, loc, cb.m_user_data);
133  abort(); // call abort in case the error callback didn't interrupt execution
134  C4_UNREACHABLE();
135 }

References c4::yml::Callbacks::m_error, and c4::yml::Callbacks::m_user_data.

Referenced by c4::yml::WriterBuf::_get(), and error().

◆ error() [2/2]

void c4::yml::error ( const char *  msg,
size_t  msg_len,
Location  loc 
)

Definition at line 139 of file common.cpp.

140 {
141  error(s_default_callbacks, msg, msg_len, loc);
142  C4_UNREACHABLE();
143 }
void error(const char *msg, size_t msg_len, Location loc)
Definition: common.cpp:139

References error().

◆ _is_indented_block()

bool c4::yml::_is_indented_block ( csubstr  s,
size_t  prev,
size_t  i 
)
inlinenoexcept

Definition at line 693 of file emit.def.hpp.

694 {
695  if(prev == 0 && s.begins_with_any(" \t"))
696  return true;
697  const size_t pos = s.first_not_of('\n', i);
698  return (pos != npos) && (s.str[pos] == ' ' || s.str[pos] == '\t');
699 }

References npos.

◆ read() [1/4]

template<class T >
std::enable_if<std::is_floating_point<T>::value, bool>::type c4::yml::read ( ConstNodeRef const &  n,
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 1707 of file node.hpp.

1708 {
1709  csubstr val = n.val();
1710  if(val.empty())
1711  return false;
1712  return from_chars_float(val, v);
1713 }
bool from_chars_float(csubstr buf, T *val)
decode a floating point from string.
Definition: tree.hpp:60

References from_chars_float(), and c4::yml::detail::RoNodeMethods< Impl, ConstImpl >::val().

◆ _find_last_newline_and_larger_indentation()

size_t c4::yml::_find_last_newline_and_larger_indentation ( csubstr  s,
size_t  indentation 
)
noexcept

Definition at line 132 of file parse.cpp.

133 {
134  if(indentation + 1 > s.len)
135  return npos;
136  for(size_t i = s.len-indentation-1; i != size_t(-1); --i)
137  {
138  if(s.str[i] == '\n')
139  {
140  csubstr rem = s.sub(i + 1);
141  size_t first = rem.first_not_of(' ');
142  first = (first != npos) ? first : rem.len;
143  if(first > indentation)
144  return i;
145  }
146  }
147  return npos;
148 }

References npos.

◆ 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:1385
@ MAP
a map: a parent of KEYVAL/KEYSEQ/KEYMAP nodes
Definition: node_type.hpp:35
Key< K > key(K &k)
Definition: node.hpp:43

References c4::yml::NodeRef::append_child(), key(), and MAP.

◆ read() [2/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 
)

Definition at line 29 of file map.hpp.

30 {
31  K k{};
32  V v{};
33  for(auto const& C4_RESTRICT ch : n)
34  {
35  ch >> c4::yml::key(k);
36  ch >> v;
37  m->emplace(std::make_pair(std::move(k), std::move(v)));
38  }
39  return true;
40 }

References key().

◆ 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:36

References c4::yml::NodeRef::append_child(), and SEQ.

◆ read() [3/4]

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

Definition at line 25 of file vector.hpp.

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

References c4::yml::detail::RoNodeMethods< Impl, ConstImpl >::num_children().

◆ read() [4/4]

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

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

Definition at line 39 of file vector.hpp.

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

References c4::yml::detail::RoNodeMethods< Impl, ConstImpl >::num_children().

◆ to_chars_float()

template<class T >
size_t c4::yml::to_chars_float ( substr  buf,
val 
)

encode a floating point value to a string.

Definition at line 42 of file tree.hpp.

43 {
44  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wfloat-equal");
45  static_assert(std::is_floating_point<T>::value, "must be floating point");
46  if(C4_UNLIKELY(std::isnan(val)))
47  return to_chars(buf, csubstr(".nan"));
48  else if(C4_UNLIKELY(val == std::numeric_limits<T>::infinity()))
49  return to_chars(buf, csubstr(".inf"));
50  else if(C4_UNLIKELY(val == -std::numeric_limits<T>::infinity()))
51  return to_chars(buf, csubstr("-.inf"));
52  return to_chars(buf, val);
53  C4_SUPPRESS_WARNING_GCC_CLANG_POP
54 }
size_t to_chars(ryml::substr buf, vec2< T > v)

References sample::to_chars().

Referenced by c4::yml::Tree::to_arena().

◆ from_chars_float()

template<class T >
bool c4::yml::from_chars_float ( csubstr  buf,
T *  val 
)

decode a floating point from string.

Accepts special values: .nan, .inf, -.inf

Definition at line 60 of file tree.hpp.

61 {
62  static_assert(std::is_floating_point<T>::value, "must be floating point");
63  if(C4_LIKELY(from_chars(buf, val)))
64  {
65  return true;
66  }
67  else if(C4_UNLIKELY(buf.begins_with('+')))
68  {
69  return from_chars(buf.sub(1), val);
70  }
71  else if(C4_UNLIKELY(buf == ".nan" || buf == ".NaN" || buf == ".NAN"))
72  {
73  *val = std::numeric_limits<T>::quiet_NaN();
74  return true;
75  }
76  else if(C4_UNLIKELY(buf == ".inf" || buf == ".Inf" || buf == ".INF"))
77  {
78  *val = std::numeric_limits<T>::infinity();
79  return true;
80  }
81  else if(C4_UNLIKELY(buf == "-.inf" || buf == "-.Inf" || buf == "-.INF"))
82  {
83  *val = -std::numeric_limits<T>::infinity();
84  return true;
85  }
86  else
87  {
88  return false;
89  }
90 }
bool from_chars(ryml::csubstr buf, vec2< T > *v)

References sample::from_chars().

Referenced by read().