450{
451 _RYML_ASSERT_BASIC_(callbacks, !buf.overlaps(tag));
452 TagDirective
const* C4_RESTRICT td =
lookup(tag,
id);
453 *bufsz = 0;
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;
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;
482 }
483 return tag.sub(1);
484 }
485 else if(tag.begins_with("!!"))
486 {
487 _c4dbgp("tagd: !!");
490 {
491 _c4dbgpf(
"tagd: standard tag: {} -> {}", tag,
from_tag_long(tagenum));
493 return with_brackets ? tag : tag.offs(1, 1);
494 }
495 handle = "!!";
496 prefix = "tag:yaml.org,2002:";
497 }
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;
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
csubstr from_tag_long(YamlTag_e tag)
YamlTag_e
a bit mask for marking tags for types
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...
YamlTag_e to_tag(csubstr tag)
TagDirective const * lookup(csubstr tag, id_type id) const noexcept