rapidyaml  0.16.0
parseandemitYAML,anddoitfast
c4::yml::TagDirectives Struct Reference

#include <tag.hpp>

Public Member Functions

bool redefines_qmrk () const noexcept
 
TagDirective const * add (csubstr handle, csubstr prefix, id_type doc_id) noexcept
 
void clear () noexcept
 
id_type size () const noexcept
 
TagDirective const * lookup (csubstr tag, id_type id) const noexcept
 
TagDirective * begin () noexcept
 
TagDirective * end () noexcept
 
TagDirective const * begin () const noexcept
 
TagDirective const * end () const noexcept
 
TagDirectiveRange directives () const noexcept
 
TagDirectiveRange lookup_range (id_type doc_id) const noexcept
 
csubstr resolve (substr buf, size_t *bufsz, csubstr tag, id_type doc_id, Location const &ymlloc, Callbacks const &callbacks, bool with_brackets=true) const
 

Public Attributes

TagDirective m_directives [RYML_MAX_TAG_DIRECTIVES]
 

Detailed Description

Definition at line 125 of file tag.hpp.

Member Function Documentation

bool c4::yml::TagDirectives::redefines_qmrk ( ) const
noexcept
TagDirective const * c4::yml::TagDirectives::add ( csubstr  handle,
csubstr  prefix,
id_type  doc_id 
)
noexcept

Definition at line 360 of file tag.cpp.

Referenced by c4::yml::extra::EventHandlerInts::add_directive_tag().

361 {
362  id_type pos = size();
363  TagDirective *C4_RESTRICT td = nullptr;
364  if(pos < RYML_MAX_TAG_DIRECTIVES)
365  {
366  td = &m_directives[pos];
367  td->handle = handle;
368  td->prefix = prefix;
369  td->doc_id = doc_id;
370  _c4dbgpf("tagd[{}]: added! handle={} prefix={} doc={}", pos, td->handle, td->prefix, td->doc_id);
371  }
372  return td;
373 }
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
id_type size() const noexcept
Definition: tag.cpp:350
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition: tag.hpp:26
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
csubstr handle
Eg.
Definition: tag.hpp:109
void c4::yml::TagDirectives::clear ( )
noexcept

Definition at line 375 of file tag.cpp.

Referenced by c4::yml::extra::EventHandlerInts::reset().

376 {
377  for(TagDirective &td : m_directives)
378  {
379  td.handle = {};
380  td.prefix = {};
381  td.doc_id = NONE;
382  }
383 }
an index to none
Definition: common.hpp:131
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
id_type c4::yml::TagDirectives::size ( ) const
noexcept

Definition at line 350 of file tag.cpp.

351 {
352  // this assumes we have a very small number of tag directives
353  id_type i = 0;
354  for(; i < RYML_MAX_TAG_DIRECTIVES; ++i)
355  if(m_directives[i].handle.empty())
356  break;
357  return i;
358 }
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition: tag.hpp:26
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
TagDirective const * c4::yml::TagDirectives::lookup ( csubstr  tag,
id_type  id 
) const
noexcept

Definition at line 421 of file tag.cpp.

Referenced by resolve().

422 {
423  _c4dbgpf("tagd: searching for {}, doc_id={}", prs_(tag), doc_id);
424  for(id_type i = 0; i < RYML_MAX_TAG_DIRECTIVES; ++i)
425  {
426  TagDirective const& C4_RESTRICT td = m_directives[i];
427  if(td.handle.empty())
428  {
429  continue;
430  }
431  _c4dbgpf("tagd[{}]: handle={} prefix={} doc_id={}", i, td.handle, td.prefix, td.doc_id);
432  if(tag.begins_with(td.handle))
433  {
434  if(td.handle == '!' && (
435  tag.begins_with("!!")
436  || tag.begins_with('<')
437  || tag.begins_with("!<")
438  || is_custom_tag(tag)))
439  continue;
440  _c4dbgpf("tagd[{}]: matches handle!", i);
441  if(doc_id == td.doc_id)
442  {
443  _c4dbgpf("tagd[{}]: matches doc={}!", i, doc_id);
444  return &td;
445  }
446  }
447  }
448  return nullptr;
449 }
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition: tag.hpp:26
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
bool is_custom_tag(csubstr tag)
is a tag of the form !handle!tag?
Definition: tag.cpp:9
TagDirective* c4::yml::TagDirectives::begin ( )
inlinenoexcept

Definition at line 133 of file tag.hpp.

133 { return m_directives; }
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
TagDirective* c4::yml::TagDirectives::end ( )
inlinenoexcept

Definition at line 134 of file tag.hpp.

134 { return m_directives + size(); }
id_type size() const noexcept
Definition: tag.cpp:350
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
TagDirective const* c4::yml::TagDirectives::begin ( ) const
inlinenoexcept

Definition at line 135 of file tag.hpp.

135 { return m_directives; }
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
TagDirective const* c4::yml::TagDirectives::end ( ) const
inlinenoexcept

Definition at line 136 of file tag.hpp.

136 { return m_directives + size(); }
id_type size() const noexcept
Definition: tag.cpp:350
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
TagDirectiveRange c4::yml::TagDirectives::directives ( ) const
inlinenoexcept

Definition at line 137 of file tag.hpp.

137 { return TagDirectiveRange{m_directives, m_directives + size()}; }
id_type size() const noexcept
Definition: tag.cpp:350
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
TagDirectiveRange c4::yml::TagDirectives::lookup_range ( id_type  doc_id) const
noexcept

Definition at line 385 of file tag.cpp.

386 {
387  TagDirective const* first = nullptr;
388  TagDirective const* last = nullptr;
389  for(id_type i = 0; i < RYML_MAX_TAG_DIRECTIVES; ++i)
390  {
391  TagDirective const& C4_RESTRICT td = m_directives[i];
392  if(doc_id == td.doc_id)
393  {
394  first = m_directives + i;
395  break;
396  }
397  else if(td.handle.empty())
398  {
399  break;
400  }
401  }
402  if(first)
403  {
405  for(TagDirective const* C4_RESTRICT td = first; td < last; ++td)
406  {
407  if(doc_id != td->doc_id || td->handle.empty())
408  {
409  last = td;
410  break;
411  }
412  }
413  }
414  else
415  {
416  first = last = m_directives;
417  }
418  return TagDirectiveRange{first, last};
419 }
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition: tag.hpp:26
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition: tag.hpp:127
csubstr c4::yml::TagDirectives::resolve ( substr  buf,
size_t *  bufsz,
csubstr  tag,
id_type  doc_id,
Location const &  ymlloc,
Callbacks const &  callbacks,
bool  with_brackets = true 
) const
Note
the str member of the return value may be null, meaning that the buffer was not enough to fit the transformed tag.
the return value may actually be not a substring of the input buffer.

Definition at line 451 of file tag.cpp.

452 {
453  RYML_ASSERT_BASIC_CB_(callbacks, !buf.overlaps(tag));
454  TagDirective const* C4_RESTRICT td = lookup(tag, id);
455  *bufsz = 0;
456  csubstr handle, prefix, ret;
457  const char *errmsg = nullptr;
458  size_t len;
459  if(td)
460  {
461  handle = td->handle;
462  prefix = td->prefix;
463  }
464  else
465  {
466  _c4dbgp("tagd: no directive found");
467  if(tag.begins_with('<'))
468  {
469  _c4dbgp("tagd: already resolved");
470  if C4_UNLIKELY(!tag.ends_with('>'))
471  {
472  errmsg = "malformed tag";
473  goto err; // NOLINT
474  }
475  return tag;
476  }
477  else if(tag.begins_with("!<"))
478  {
479  _c4dbgp("tagd: already resolved");
480  if C4_UNLIKELY(!tag.ends_with('>'))
481  {
482  errmsg = "malformed tag";
483  goto err; // NOLINT
484  }
485  return tag.sub(1);
486  }
487  else if(tag.begins_with("!!"))
488  {
489  _c4dbgp("tagd: !!");
490  YamlTag_e tagenum = to_tag(tag);
491  if(tagenum != TAG_NONE)
492  {
493  _c4dbgpf("tagd: standard tag: {} -> {}", tag, from_tag_long(tagenum));
494  tag = from_tag_long(tagenum);
495  return with_brackets ? tag : tag.offs(1, 1);
496  }
497  handle = "!!";
498  prefix = "tag:yaml.org,2002:";
499  }
500  else if C4_UNLIKELY(is_custom_tag(tag))
501  {
502  _c4dbgp("tagd: custom_tag");
503  _c4dbgpf("tag '{}' at id={}: no matching directive was found", tag, id);
504  errmsg = "tag without matching directive";
505  goto err; // NOLINT
506  }
507  else
508  {
509  _c4dbgp("tagd: !");
510  handle = prefix = "!";
511  }
512  }
513  len = transform_tag(buf, handle, prefix, tag, callbacks, ymlloc, with_brackets);
514  *bufsz = len;
515  if(len <= buf.len)
516  {
517  ret = buf.first(len);
518  }
519  else
520  {
521  _c4dbgp("tagd: not enough room");
522  ret.str = nullptr;
523  ret.len = len;
524  }
525  return ret;
526 err:
527  if(ymlloc)
528  {
529  RYML_ERR_PARSE_CB_(callbacks, ymlloc, errmsg);
530  }
531  else
532  {
533  RYML_ERR_BASIC_CB_(callbacks, errmsg);
534  }
535 }
size_t transform_tag(substr output, csubstr handle, csubstr prefix, csubstr tag, Callbacks const &callbacks, Location const &ymlloc, bool with_brackets)
returns the length of the transformed tag, or 0 to signal that the tag is local and cannot be resolve...
Definition: tag.cpp:287
csubstr from_tag_long(YamlTag_e tag)
Definition: tag.cpp:130
basic_substring< const char > csubstr
an immutable string view
Definition: substr.hpp:2356
YamlTag_e
a bit mask for marking tags for types
Definition: tag.hpp:33
TagDirective const * lookup(csubstr tag, id_type id) const noexcept
Definition: tag.cpp:421
bool is_custom_tag(csubstr tag)
is a tag of the form !handle!tag?
Definition: tag.cpp:9
YamlTag_e to_tag(csubstr tag)
Definition: tag.cpp:68

Member Data Documentation

TagDirective c4::yml::TagDirectives::m_directives[RYML_MAX_TAG_DIRECTIVES]

Definition at line 127 of file tag.hpp.

Referenced by clear(), and size().


The documentation for this struct was generated from the following files: