Refactored tags so we can emit secondary tags (and named local tags)

This commit is contained in:
Jesse Beder
2010-10-28 23:06:16 +00:00
parent d508203ed8
commit a6afaabcb0
4 changed files with 70 additions and 27 deletions

View File

@@ -680,27 +680,31 @@ namespace YAML
{
if(!good())
return *this;
EmitTag(tag.verbatim, tag);
return *this;
}
void Emitter::EmitTag(bool verbatim, const _Tag& tag)
{
PreAtomicWrite();
EmitSeparationIfNecessary();
if(!Utils::WriteTag(m_stream, tag.content, verbatim)) {
bool success = false;
if(tag.type == _Tag::Type::Verbatim)
success = Utils::WriteTag(m_stream, tag.content, true);
else if(tag.type == _Tag::Type::PrimaryHandle)
success = Utils::WriteTag(m_stream, tag.content, false);
else
success = Utils::WriteTagWithPrefix(m_stream, tag.prefix, tag.content);
if(!success) {
m_pState->SetError(ErrorMsg::INVALID_TAG);
return;
return *this;
}
m_pState->RequireSeparation();
// Note: no PostAtomicWrite() because we need another value for this node
return *this;
}
void Emitter::EmitKindTag()
{
_Tag tag("");
EmitTag(false, tag);
Write(LocalTag(""));
}
Emitter& Emitter::Write(const _Comment& comment)
@@ -727,10 +731,10 @@ namespace YAML
Emitter& Emitter::Write(const _Binary& binary)
{
Write(SecondaryTag("binary"));
if(!good())
return *this;
// TODO: write tag !!binary
PreAtomicWrite();
EmitSeparationIfNecessary();