This commit is contained in:
Rosen Penev 2022-05-28 09:48:12 +09:00 committed by GitHub
commit 123a86d99b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 30 additions and 46 deletions

View File

@ -44,7 +44,7 @@ class YAML_CPP_API Emitter {
// state checking // state checking
bool good() const; bool good() const;
const std::string GetLastError() const; std::string GetLastError() const;
// global setters // global setters
bool SetOutputCharset(EMITTER_MANIP value); bool SetOutputCharset(EMITTER_MANIP value);
@ -126,7 +126,6 @@ class YAML_CPP_API Emitter {
const char* ComputeFullBoolName(bool b) const; const char* ComputeFullBoolName(bool b) const;
const char* ComputeNullName() const; const char* ComputeNullName() const;
bool CanEmitNewline() const;
private: private:
std::unique_ptr<EmitterState> m_pState; std::unique_ptr<EmitterState> m_pState;

View File

@ -3,8 +3,7 @@
namespace YAML { namespace YAML {
Directives::Directives() : version{true, 1, 2}, tags{} {} Directives::Directives() : version{true, 1, 2}, tags{} {}
const std::string Directives::TranslateTagHandle( std::string Directives::TranslateTagHandle(const std::string& handle) const {
const std::string& handle) const {
auto it = tags.find(handle); auto it = tags.find(handle);
if (it == tags.end()) { if (it == tags.end()) {
if (handle == "!!") if (handle == "!!")

View File

@ -19,7 +19,7 @@ struct Version {
struct Directives { struct Directives {
Directives(); Directives();
const std::string TranslateTagHandle(const std::string& handle) const; std::string TranslateTagHandle(const std::string& handle) const;
Version version; Version version;
std::map<std::string, std::string> tags; std::map<std::string, std::string> tags;

View File

@ -25,9 +25,7 @@ std::size_t Emitter::size() const { return m_stream.pos(); }
// state checking // state checking
bool Emitter::good() const { return m_pState->good(); } bool Emitter::good() const { return m_pState->good(); }
const std::string Emitter::GetLastError() const { std::string Emitter::GetLastError() const { return m_pState->GetLastError(); }
return m_pState->GetLastError();
}
// global setters // global setters
bool Emitter::SetOutputCharset(EMITTER_MANIP value) { bool Emitter::SetOutputCharset(EMITTER_MANIP value) {
@ -271,8 +269,6 @@ void Emitter::EmitNewline() {
m_pState->SetNonContent(); m_pState->SetNonContent();
} }
bool Emitter::CanEmitNewline() const { return true; }
// Put the stream in a state so we can simply write the next node // Put the stream in a state so we can simply write the next node
// E.g., if we're in a sequence, write the "- " // E.g., if we're in a sequence, write the "- "
void Emitter::PrepareNode(EmitterNodeType::value child) { void Emitter::PrepareNode(EmitterNodeType::value child) {

View File

@ -7,6 +7,19 @@
#include "yaml-cpp/exceptions.h" // IWYU pragma: keep #include "yaml-cpp/exceptions.h" // IWYU pragma: keep
namespace YAML { namespace YAML {
namespace {
// IsWhitespaceToBeEaten
// . We can eat whitespace if it's a space or tab
// . Note: originally tabs in block context couldn't be eaten
// "where a simple key could be allowed
// (i.e., not at the beginning of a line, or following '-', '?', or
// ':')"
// I think this is wrong, since tabs can be non-content whitespace; it's just
// that they can't contribute to indentation, so once you've seen a tab in a
// line, you can't start a simple key
bool IsWhitespaceToBeEaten(char ch) { return (ch == ' ') || (ch == '\t'); }
} // namespace
Scanner::Scanner(std::istream& in) Scanner::Scanner(std::istream& in)
: INPUT(in), : INPUT(in),
m_tokens{}, m_tokens{},
@ -213,27 +226,6 @@ void Scanner::ScanToNextToken() {
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// Misc. helpers // Misc. helpers
// IsWhitespaceToBeEaten
// . We can eat whitespace if it's a space or tab
// . Note: originally tabs in block context couldn't be eaten
// "where a simple key could be allowed
// (i.e., not at the beginning of a line, or following '-', '?', or
// ':')"
// I think this is wrong, since tabs can be non-content whitespace; it's just
// that they can't contribute to indentation, so once you've seen a tab in a
// line, you can't start a simple key
bool Scanner::IsWhitespaceToBeEaten(char ch) {
if (ch == ' ') {
return true;
}
if (ch == '\t') {
return true;
}
return false;
}
const RegEx& Scanner::GetValueRegex() const { const RegEx& Scanner::GetValueRegex() const {
if (InBlockContext()) { if (InBlockContext()) {
return Exp::Value(); return Exp::Value();
@ -269,7 +261,7 @@ Token* Scanner::PushToken(Token::TYPE type) {
return &m_tokens.back(); return &m_tokens.back();
} }
Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) const { Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) {
switch (type) { switch (type) {
case IndentMarker::SEQ: case IndentMarker::SEQ:
return Token::BLOCK_SEQ_START; return Token::BLOCK_SEQ_START;

View File

@ -88,7 +88,7 @@ class Scanner {
bool InBlockContext() const { return m_flows.empty(); } bool InBlockContext() const { return m_flows.empty(); }
std::size_t GetFlowLevel() const { return m_flows.size(); } std::size_t GetFlowLevel() const { return m_flows.size(); }
Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type) const; static Token::TYPE GetStartTokenFor(IndentMarker::INDENT_TYPE type);
/** /**
* Pushes an indentation onto the stack, and enqueues the proper token * Pushes an indentation onto the stack, and enqueues the proper token
@ -129,8 +129,6 @@ class Scanner {
*/ */
void ThrowParserException(const std::string &msg) const; void ThrowParserException(const std::string &msg) const;
bool IsWhitespaceToBeEaten(char ch);
/** /**
* Returns the appropriate regex to check if the next token is a value token. * Returns the appropriate regex to check if the next token is a value token.
*/ */

View File

@ -6,7 +6,7 @@
#include "yaml-cpp/mark.h" #include "yaml-cpp/mark.h"
namespace YAML { namespace YAML {
const std::string ScanVerbatimTag(Stream& INPUT) { std::string ScanVerbatimTag(Stream& INPUT) {
std::string tag; std::string tag;
// eat the start character // eat the start character
@ -29,7 +29,7 @@ const std::string ScanVerbatimTag(Stream& INPUT) {
throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG); throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
} }
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) { std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
std::string tag; std::string tag;
canBeHandle = true; canBeHandle = true;
Mark firstNonWordChar; Mark firstNonWordChar;
@ -62,7 +62,7 @@ const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) {
return tag; return tag;
} }
const std::string ScanTagSuffix(Stream& INPUT) { std::string ScanTagSuffix(Stream& INPUT) {
std::string tag; std::string tag;
while (INPUT) { while (INPUT) {

View File

@ -11,9 +11,9 @@
#include "stream.h" #include "stream.h"
namespace YAML { namespace YAML {
const std::string ScanVerbatimTag(Stream& INPUT); std::string ScanVerbatimTag(Stream& INPUT);
const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle); std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle);
const std::string ScanTagSuffix(Stream& INPUT); std::string ScanTagSuffix(Stream& INPUT);
} }
#endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66 #endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66

View File

@ -93,9 +93,9 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) {
// add non-specific tags // add non-specific tags
if (tag.empty()) if (tag.empty())
tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?"); tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?");
if (token.type == Token::PLAIN_SCALAR if (token.type == Token::PLAIN_SCALAR && tag == "?" &&
&& tag.compare("?") == 0 && IsNullString(token.value)) { IsNullString(token.value)) {
eventHandler.OnNull(mark, anchor); eventHandler.OnNull(mark, anchor);
m_scanner.pop(); m_scanner.pop();
return; return;

View File

@ -29,7 +29,7 @@ Tag::Tag(const Token& token)
} }
} }
const std::string Tag::Translate(const Directives& directives) { std::string Tag::Translate(const Directives& directives) const {
switch (type) { switch (type) {
case VERBATIM: case VERBATIM:
return value; return value;

View File

@ -23,7 +23,7 @@ struct Tag {
}; };
Tag(const Token& token); Tag(const Token& token);
const std::string Translate(const Directives& directives); std::string Translate(const Directives& directives) const;
TYPE type; TYPE type;
std::string handle, value; std::string handle, value;