From 6a2b861b1d1b17d3df16684410be21eed7881deb Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 19 Jan 2016 00:31:11 -0500 Subject: [PATCH] C++11: Improved CppCoreGuidelines compliance --- src/Pig.cpp | 9 ++++----- src/Pig.h | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Pig.cpp b/src/Pig.cpp index 2b67069d..eb3aa7a3 100644 --- a/src/Pig.cpp +++ b/src/Pig.cpp @@ -35,9 +35,7 @@ //////////////////////////////////////////////////////////////////////////////// Pig::Pig (const std::string& text) -: _text (text) -, _cursor (0) -, _saved (0) +: _text {text} { } @@ -217,6 +215,7 @@ bool Pig::getDigits (int& result) _cursor = prev; break; } + prev = _cursor; } @@ -419,7 +418,7 @@ bool Pig::getOneOf ( const std::vector & options, std::string& found) { - for (auto& option : options) + for (const auto& option : options) { if (skipLiteral (option)) { @@ -469,7 +468,7 @@ std::string Pig::peek (const int quantity) const } //////////////////////////////////////////////////////////////////////////////// -std::string::size_type Pig::cursor () +std::string::size_type Pig::cursor () const { return _cursor; } diff --git a/src/Pig.h b/src/Pig.h index 00cc98e7..4f719af3 100644 --- a/src/Pig.h +++ b/src/Pig.h @@ -33,7 +33,7 @@ class Pig { public: - Pig (const std::string&); + explicit Pig (const std::string&); bool skip (int); bool skipN (const int quantity = 1); @@ -56,7 +56,7 @@ public: bool eos () const; int peek () const; std::string peek (const int) const; - std::string::size_type cursor (); + std::string::size_type cursor () const; std::string::size_type save (); std::string::size_type restore (); @@ -64,8 +64,8 @@ public: private: const std::string& _text; - std::string::size_type _cursor; - std::string::size_type _saved; + std::string::size_type _cursor {0}; + std::string::size_type _saved {0}; }; #endif