Skip to content
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

[clang-tidy] several const changes #896

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions include/yaml-cpp/emitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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);
Expand Down Expand Up @@ -126,7 +126,6 @@ class YAML_CPP_API Emitter {

const char* ComputeFullBoolName(bool b) const;
const char* ComputeNullName() const;
bool CanEmitNewline() const;

private:
std::unique_ptr<EmitterState> m_pState;
Expand Down
3 changes: 1 addition & 2 deletions src/directives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace YAML {
Directives::Directives() : version{true, 1, 2}, tags{} {}

const std::string Directives::TranslateTagHandle(
const std::string& handle) const {
std::string Directives::TranslateTagHandle(const std::string& handle) const {
auto it = tags.find(handle);
if (it == tags.end()) {
if (handle == "!!")
Expand Down
2 changes: 1 addition & 1 deletion src/directives.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct Version {
struct Directives {
Directives();

const std::string TranslateTagHandle(const std::string& handle) const;
std::string TranslateTagHandle(const std::string& handle) const;

Version version;
std::map<std::string, std::string> tags;
Expand Down
6 changes: 1 addition & 5 deletions src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -271,8 +269,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) {
Expand Down
36 changes: 14 additions & 22 deletions src/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down Expand Up @@ -213,27 +226,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();
Expand Down Expand Up @@ -269,7 +261,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;
Expand Down
4 changes: 1 addition & 3 deletions src/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is only used in the .cpp file; can you just put it in an anonymous namespace there (rather than making it a static member function)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses INDENT_TYPE , which is declared private.


/**
* Pushes an indentation onto the stack, and enqueues the proper token
Expand Down Expand Up @@ -131,8 +131,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.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/scantag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/scantag.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions src/singledocparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ void SingleDocParser::HandleNode(EventHandler& eventHandler) {
// add non-specific tags
if (tag.empty())
tag = (token.type == Token::NON_PLAIN_SCALAR ? "!" : "?");
if (token.type == Token::PLAIN_SCALAR
&& tag.compare("?") == 0 && IsNullString(token.value)) {

if (token.type == Token::PLAIN_SCALAR && tag == "?" &&
IsNullString(token.value)) {
eventHandler.OnNull(mark, anchor);
m_scanner.pop();
return;
Expand Down
2 changes: 1 addition & 1 deletion src/tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
case VERBATIM:
return value;
Expand Down
2 changes: 1 addition & 1 deletion src/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Tag {
};

Tag(const Token& token);
const std::string Translate(const Directives& directives);
std::string Translate(const Directives& directives) const;

TYPE type;
std::string handle, value;
Expand Down