-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FR: Provide API for emit+append #345
Comments
It does make sense, but I'm not inclined to add that, as the emit overload set is already too large. Also, you can already achieve this by using the lower level template<class CharOwningContainer>
substr emitrs_json(Tree const& t, size_t id, CharOwningContainer * cont)
{
substr buf = to_substr(*cont);
substr ret = emit_json(t, id, buf, /*error_on_excess*/false);
if(ret.str == nullptr && ret.len > 0)
{
cont->resize(ret.len);
buf = to_substr(*cont);
ret = emit_json(t, id, buf, /*error_on_excess*/true);
}
return ret;
} Using this as a starting point, and assuming we will append after template<class CharOwningContainer>
substr emitrs_json_append(Tree const& t, size_t id, CharOwningContainer * cont)
{
size_t sz = cont->size(); // save the original container size
cont->resize(cont->capacity()); // expand the container to its current capacity
// to give us a chance to not allocate
substr buf = to_substr(*cont); // get the full view as above
buf = buf.sub(sz); // but skip the original container size
// (retain only at the end)
substr ret = emit_json(t, id, buf, /*error_on_excess*/false);
if(ret.str == nullptr && ret.len > 0)
{
cont->resize(sz + ret.len); // original + needed size
buf = to_substr(*cont);
buf = buf.sub(sz); // skip the original size
ret = emit_json(t, id, buf, /*error_on_excess*/true);
}
return ret;
}
template<class CharOwningContainer>
substr emitrs_json_append(ConstNodeRef const &n, CharOwningContainer * cont)
{
return emitrs_json_append(n.tree(), n.id(), cont);
} HTH. |
I think the |
That's just not going to happen. But while working on an unrelated issue, I've had to create an |
See the commit/PR linked above. It will land in master in a few weeks. |
Thanks! |
Currently
emitrs_json(ConstNodeRef const& n, CharOwningContainer * cont)
will overwrite the original content ofcont
.May I request an API to keep the content of
cont
but append emitted string tocont
.The text was updated successfully, but these errors were encountered: