Mercurial > public > cpp-enigma
diff enigma/plugboard.cpp @ 6:3370383116db
Bug fix for the string functions.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 26 Jun 2012 21:22:42 -0500 |
parents | f4e25e6b76c3 |
children |
line wrap: on
line diff
--- a/enigma/plugboard.cpp Sun Jun 24 19:22:06 2012 -0500 +++ b/enigma/plugboard.cpp Tue Jun 26 21:22:42 2012 -0500 @@ -134,13 +134,17 @@ std::string s; - for (const auto p : pairs) + for (const auto& p : pairs) { s += static_cast<char>(p.first + 'A'); s += static_cast<char>(p.second + 'A'); s += ' '; } - s.erase(s.size() - 1); // erase trailing space + + if (!s.empty()) + { + s.erase(s.size() - 1); // erase trailing space + } return s; } @@ -151,13 +155,16 @@ const auto pairs = get_pairs(); std::ostringstream os; - for (const auto p : pairs) + for (const auto& p : pairs) { os << (p.first + 1) << '/' << (p.second + 1) << ' '; } std::string s(os.str()); - s.erase(s.size() - 1); // erase trailing space + if (!s.empty()) + { + s.erase(s.size() - 1); // erase trailing space + } return s; }