Skip to content

Commit

Permalink
Added support for emitting and represeting null
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeder committed Jul 30, 2009
1 parent 72919ad commit ae41e58
Show file tree
Hide file tree
Showing 10 changed files with 576 additions and 514 deletions.
4 changes: 4 additions & 0 deletions include/conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define CONVERSION_H_62B23520_7C8E_11DE_8A39_0800200C9A66


#include "null.h"
#include <string>
#include <sstream>

Expand Down Expand Up @@ -37,6 +38,9 @@ namespace YAML
template <>
bool Converter<bool>::Convert(const std::string& input, bool& output);

template <>
bool Converter<_Null>::Convert(const std::string& input, _Null& output);

template <>
bool Converter<std::wstring>::Convert(const std::string& input, std::wstring& output);
}
Expand Down
2 changes: 2 additions & 0 deletions include/emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "emittermanip.h"
#include "ostream.h"
#include "null.h"
#include <memory>
#include <string>

Expand Down Expand Up @@ -51,6 +52,7 @@ namespace YAML
Emitter& Write(const _Alias& alias);
Emitter& Write(const _Anchor& anchor);
Emitter& Write(const _Comment& comment);
Emitter& Write(const _Null& null);

private:
enum ATOMIC_TYPE { AT_SCALAR, AT_SEQ, AT_BLOCK_SEQ, AT_FLOW_SEQ, AT_MAP, AT_BLOCK_MAP, AT_FLOW_MAP };
Expand Down
13 changes: 13 additions & 0 deletions include/null.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#ifndef NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66


namespace YAML
{
struct _Null {};
extern _Null Null;
}

#endif // NULL_H_62B23520_7C8E_11DE_8A39_0800200C9A66
6 changes: 6 additions & 0 deletions src/conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ namespace YAML
return false;
}

template <>
bool Converter<_Null>::Convert(const std::string& input, _Null& /*output*/)
{
return input.empty() || input == "~" || input == "null" || input == "Null" || input == "NULL";
}

template <>
bool Converter<std::wstring>::Convert(const std::string& input, std::wstring& output)
{
Expand Down
12 changes: 12 additions & 0 deletions src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,4 +666,16 @@ namespace YAML
Utils::WriteComment(m_stream, comment.content, m_pState->GetPostCommentIndent());
return *this;
}

Emitter& Emitter::Write(const _Null& /*null*/)
{
if(!good())
return *this;

PreAtomicWrite();
EmitSeparationIfNecessary();
m_stream << "~";
PostAtomicWrite();
return *this;
}
}
4 changes: 4 additions & 0 deletions src/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "aliascontent.h"
#include "iterpriv.h"
#include "emitter.h"
#include <stdexcept>

namespace YAML
{
Expand Down Expand Up @@ -85,6 +86,9 @@ namespace YAML
m_pContent = new Map;
break;
default:
// std::stringstream str;
// str << TokenNames[pScanner->peek().type];
// throw std::runtime_error(str.str());
break;
}

Expand Down
6 changes: 6 additions & 0 deletions src/null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "null.h"

namespace YAML
{
_Null Null;
}
Loading

0 comments on commit ae41e58

Please sign in to comment.