452{
453 RYML_ASSERT_BASIC_CB_(callbacks, !buf.overlaps(tag));
454 TagDirective
const* C4_RESTRICT td =
lookup(tag,
id);
455 *bufsz = 0;
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;
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;
484 }
486 }
487 else if(tag.begins_with("!!"))
488 {
489 _c4dbgp("tagd: !!");
492 {
493 _c4dbgpf(
"tagd: standard tag: {} -> {}", tag,
from_tag_long(tagenum));
495 return with_brackets ? tag : tag.offs(1, 1);
496 }
497 handle = "!!";
498 prefix = "tag:yaml.org,2002:";
499 }
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;
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;
526err:
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}
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)
basic_substring sub(size_t first) const noexcept
return [first,len[
TagDirective const * lookup(csubstr tag, id_type id) const noexcept