mirror of
https://github.com/biojppm/rapidyaml.git
synced 2026-01-18 21:41:18 +01:00
tag.hpp: move tree-aware functions to the tree
This commit is contained in:
@@ -221,24 +221,6 @@ bool TagDirective::create_from_str(csubstr directive_)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TagDirective::create_from_str(csubstr directive_, Tree *tree)
|
||||
{
|
||||
_RYML_CB_CHECK(tree->callbacks(), directive_.begins_with("%TAG "));
|
||||
if(!create_from_str(directive_))
|
||||
{
|
||||
_RYML_CB_ERR(tree->callbacks(), "invalid tag directive");
|
||||
}
|
||||
next_node_id = tree->size();
|
||||
if(!tree->empty())
|
||||
{
|
||||
const id_type prev = tree->size() - 1;
|
||||
if(tree->is_root(prev) && tree->type(prev) != NOTYPE && !tree->is_stream(prev))
|
||||
++next_node_id;
|
||||
}
|
||||
_c4dbgpf("%TAG: handle={} prefix={} next_node={}", handle, prefix, next_node_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t TagDirective::transform(csubstr tag, substr output, Callbacks const& callbacks) const
|
||||
{
|
||||
_c4dbgpf("%TAG: handle={} prefix={} next_node={}. tag={}", handle, prefix, next_node_id, tag);
|
||||
|
||||
@@ -64,7 +64,6 @@ struct RYML_EXPORT TagDirective
|
||||
id_type next_node_id;
|
||||
|
||||
bool create_from_str(csubstr directive_); ///< leaves next_node_id unfilled
|
||||
bool create_from_str(csubstr directive_, Tree *tree);
|
||||
size_t transform(csubstr tag, substr output, Callbacks const& callbacks) const;
|
||||
};
|
||||
|
||||
|
||||
@@ -1397,10 +1397,30 @@ id_type Tree::add_tag_directive(TagDirective const& td)
|
||||
return pos;
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool _create_tag_directive_from_str(csubstr directive_, TagDirective *td, Tree *tree)
|
||||
{
|
||||
_RYML_CB_CHECK(tree->callbacks(), directive_.begins_with("%TAG "));
|
||||
if(!td->create_from_str(directive_))
|
||||
{
|
||||
_RYML_CB_ERR(tree->callbacks(), "invalid tag directive");
|
||||
}
|
||||
td->next_node_id = tree->size();
|
||||
if(!tree->empty())
|
||||
{
|
||||
const id_type prev = tree->size() - 1;
|
||||
if(tree->is_root(prev) && tree->type(prev) != NOTYPE && !tree->is_stream(prev))
|
||||
++td->next_node_id;
|
||||
}
|
||||
_c4dbgpf("%TAG: handle={} prefix={} next_node={}", td->handle, td->prefix, td->next_node_id);
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
bool Tree::add_tag_directive(csubstr directive_)
|
||||
{
|
||||
TagDirective td;
|
||||
if(td.create_from_str(directive_, this))
|
||||
if(_create_tag_directive_from_str(directive_, &td, this))
|
||||
{
|
||||
add_tag_directive(td);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user