rapidyaml 0.14.0
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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
TagDirectivebegin () noexcept
TagDirectiveend () 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

◆ redefines_qmrk()

bool c4::yml::TagDirectives::redefines_qmrk ( ) const
noexcept

◆ add()

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

Definition at line 358 of file tag.cpp.

359{
360 id_type pos = size();
361 TagDirective *C4_RESTRICT td = nullptr;
363 {
364 td = &m_directives[pos];
365 td->handle = handle;
366 td->prefix = prefix;
367 td->doc_id = doc_id;
368 _c4dbgpf("tagd[{}]: added! handle={} prefix={} doc={}", pos, td->handle, td->prefix, td->doc_id);
369 }
370 return td;
371}
#define RYML_MAX_TAG_DIRECTIVES
the maximum number of tag directives in a Tree
Definition tag.hpp:26
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:249
TagDirective m_directives[RYML_MAX_TAG_DIRECTIVES]
Definition tag.hpp:127
id_type size() const noexcept
Definition tag.cpp:348

◆ clear()

void c4::yml::TagDirectives::clear ( )
noexcept

Definition at line 373 of file tag.cpp.

374{
375 for(TagDirective &td : m_directives)
376 {
377 td.handle = {};
378 td.prefix = {};
379 td.doc_id = NONE;
380 }
381}
@ NONE
an index to none
Definition common.hpp:256

◆ size()

id_type c4::yml::TagDirectives::size ( ) const
noexcept

Definition at line 348 of file tag.cpp.

349{
350 // this assumes we have a very small number of tag directives
351 id_type i = 0;
352 for(; i < RYML_MAX_TAG_DIRECTIVES; ++i)
353 if(m_directives[i].handle.empty())
354 break;
355 return i;
356}

◆ lookup()

TagDirective const * c4::yml::TagDirectives::lookup ( csubstr tag,
id_type id ) const
noexcept

Definition at line 419 of file tag.cpp.

420{
421 _c4dbgpf("tagd: searching for {}, doc_id={}", _prs(tag), doc_id);
422 for(id_type i = 0; i < RYML_MAX_TAG_DIRECTIVES; ++i)
423 {
424 TagDirective const& C4_RESTRICT td = m_directives[i];
425 if(td.handle.empty())
426 {
427 continue;
428 }
429 _c4dbgpf("tagd[{}]: handle={} prefix={} doc_id={}", i, td.handle, td.prefix, td.doc_id);
430 if(tag.begins_with(td.handle))
431 {
432 if(td.handle == '!' && (
433 tag.begins_with("!!")
434 || tag.begins_with('<')
435 || tag.begins_with("!<")
436 || is_custom_tag(tag)))
437 continue;
438 _c4dbgpf("tagd[{}]: matches handle!", i);
439 if(doc_id == td.doc_id)
440 {
441 _c4dbgpf("tagd[{}]: matches doc={}!", i, doc_id);
442 return &td;
443 }
444 }
445 }
446 return nullptr;
447}
bool is_custom_tag(csubstr tag)
is a tag of the form !handle!tag?
Definition tag.cpp:9

◆ begin() [1/2]

TagDirective * c4::yml::TagDirectives::begin ( )
inlinenoexcept

Definition at line 133 of file tag.hpp.

133{ return m_directives; }

◆ end() [1/2]

TagDirective * c4::yml::TagDirectives::end ( )
inlinenoexcept

Definition at line 134 of file tag.hpp.

134{ return m_directives + size(); }

◆ begin() [2/2]

TagDirective const * c4::yml::TagDirectives::begin ( ) const
inlinenoexcept

Definition at line 135 of file tag.hpp.

135{ return m_directives; }

◆ end() [2/2]

TagDirective const * c4::yml::TagDirectives::end ( ) const
inlinenoexcept

Definition at line 136 of file tag.hpp.

136{ return m_directives + size(); }

◆ directives()

TagDirectiveRange c4::yml::TagDirectives::directives ( ) const
inlinenoexcept

Definition at line 137 of file tag.hpp.

137{ return TagDirectiveRange{m_directives, m_directives + size()}; }

◆ lookup_range()

TagDirectiveRange c4::yml::TagDirectives::lookup_range ( id_type doc_id) const
noexcept

Definition at line 383 of file tag.cpp.

384{
385 TagDirective const* first = nullptr;
386 TagDirective const* last = nullptr;
387 for(id_type i = 0; i < RYML_MAX_TAG_DIRECTIVES; ++i)
388 {
389 TagDirective const& C4_RESTRICT td = m_directives[i];
390 if(doc_id == td.doc_id)
391 {
392 first = m_directives + i;
393 break;
394 }
395 else if(td.handle.empty())
396 {
397 break;
398 }
399 }
400 if(first)
401 {
403 for(TagDirective const* C4_RESTRICT td = first; td < last; ++td)
404 {
405 if(doc_id != td->doc_id || td->handle.empty())
406 {
407 last = td;
408 break;
409 }
410 }
411 }
412 else
413 {
414 first = last = m_directives;
415 }
416 return TagDirectiveRange{first, last};
417}

◆ resolve()

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 449 of file tag.cpp.

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

Member Data Documentation

◆ m_directives

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

Definition at line 127 of file tag.hpp.


The documentation for this struct was generated from the following files:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/v0.14.0/src/c4/yml/tag.hpp
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/v0.14.0/src/c4/yml/tag.cpp