diff --git a/include/yaml-cpp/emitter.h b/include/yaml-cpp/emitter.h index 1d4edf4da..4f07b0d8f 100644 --- a/include/yaml-cpp/emitter.h +++ b/include/yaml-cpp/emitter.h @@ -50,7 +50,7 @@ class YAML_CPP_API Emitter { // state checking bool good() const; - const std::string GetLastError() const; + std::string GetLastError() const; // global setters bool SetOutputCharset(EMITTER_MANIP value); @@ -136,7 +136,6 @@ class YAML_CPP_API Emitter { const char* ComputeFullBoolName(bool b) const; const char* ComputeNullName() const; - bool CanEmitNewline() const; private: std::unique_ptr m_pState; diff --git a/src/emitter.cpp b/src/emitter.cpp index b69f24bb7..9c7316c79 100644 --- a/src/emitter.cpp +++ b/src/emitter.cpp @@ -25,9 +25,7 @@ std::size_t Emitter::size() const { return m_stream.pos(); } // state checking bool Emitter::good() const { return m_pState->good(); } -const std::string Emitter::GetLastError() const { - return m_pState->GetLastError(); -} +std::string Emitter::GetLastError() const { return m_pState->GetLastError(); } // global setters bool Emitter::SetOutputCharset(EMITTER_MANIP value) { @@ -281,8 +279,6 @@ void Emitter::EmitNewline() { m_pState->SetNonContent(); } -bool Emitter::CanEmitNewline() const { return true; } - // Put the stream in a state so we can simply write the next node // E.g., if we're in a sequence, write the "- " void Emitter::PrepareNode(EmitterNodeType::value child) { diff --git a/src/scanner.cpp b/src/scanner.cpp index a0abd3b61..f71e72964 100644 --- a/src/scanner.cpp +++ b/src/scanner.cpp @@ -7,6 +7,19 @@ #include "yaml-cpp/exceptions.h" // IWYU pragma: keep 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) : INPUT(in), m_tokens{}, @@ -254,27 +267,6 @@ void Scanner::ScanToNextToken() { /////////////////////////////////////////////////////////////////////// // 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 { if (InBlockContext()) { return Exp::Value(); @@ -312,7 +304,7 @@ Token* Scanner::PushToken(Token::TYPE type) { return &m_tokens.back(); } -Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) const { +Token::TYPE Scanner::GetStartTokenFor(IndentMarker::INDENT_TYPE type) { switch (type) { case IndentMarker::SEQ: return Token::BLOCK_SEQ_START; diff --git a/src/scanner.h b/src/scanner.h index a3bfb662d..e9d5ba06f 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -88,7 +88,7 @@ class Scanner { bool InBlockContext() const { return m_flows.empty(); } 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 @@ -129,8 +129,6 @@ class Scanner { */ 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. */ diff --git a/src/scantag.cpp b/src/scantag.cpp index 176cc5c71..63bc1e537 100644 --- a/src/scantag.cpp +++ b/src/scantag.cpp @@ -6,7 +6,7 @@ #include "yaml-cpp/mark.h" namespace YAML { -const std::string ScanVerbatimTag(Stream& INPUT) { +std::string ScanVerbatimTag(Stream& INPUT) { std::string tag; // eat the start character @@ -29,7 +29,7 @@ const std::string ScanVerbatimTag(Stream& INPUT) { 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; canBeHandle = true; Mark firstNonWordChar; @@ -62,7 +62,7 @@ const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle) { return tag; } -const std::string ScanTagSuffix(Stream& INPUT) { +std::string ScanTagSuffix(Stream& INPUT) { std::string tag; while (INPUT) { diff --git a/src/scantag.h b/src/scantag.h index 522ba5495..9fa1684dc 100644 --- a/src/scantag.h +++ b/src/scantag.h @@ -11,9 +11,9 @@ #include "stream.h" namespace YAML { -const std::string ScanVerbatimTag(Stream& INPUT); -const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle); -const std::string ScanTagSuffix(Stream& INPUT); +std::string ScanVerbatimTag(Stream& INPUT); +std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle); +std::string ScanTagSuffix(Stream& INPUT); } #endif // SCANTAG_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/singledocparser.cpp b/src/singledocparser.cpp index c60a2e8b5..ca80bea2c 100644 --- a/src/singledocparser.cpp +++ b/src/singledocparser.cpp @@ -99,7 +99,7 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) { tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?"); if (token.type == Token::PLAIN_SCALAR - && tag.compare("?") == 0 && IsNullString(token.value.data(), token.value.size())) { + && tag == "?" && IsNullString(token.value.data(), token.value.size())) { eventHandler.OnNull(mark, anchor); m_scanner.pop(); return; diff --git a/src/tag.cpp b/src/tag.cpp index 35a1b4656..9d36317de 100644 --- a/src/tag.cpp +++ b/src/tag.cpp @@ -29,7 +29,7 @@ Tag::Tag(const Token& token) } } -std::string Tag::Translate(const Directives& directives) { +std::string Tag::Translate(const Directives& directives) const { switch (type) { case VERBATIM: return value; diff --git a/src/tag.h b/src/tag.h index c811f3955..efa77f0fb 100644 --- a/src/tag.h +++ b/src/tag.h @@ -23,7 +23,7 @@ struct Tag { }; Tag(const Token& token); - std::string Translate(const Directives& directives); + std::string Translate(const Directives& directives) const; TYPE type; std::string handle, value;