summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-05-12 02:20:44 -0400
committerJeffrey Walton <noloader@gmail.com>2017-05-12 02:20:44 -0400
commitac6db2fa91744ed995bf0abcdc43e8e80491003d (patch)
tree00039a03f1a0b3537db7d07101a97e48ad483883 /datatest.cpp
parent9850576d0bf11da867fdec45257f0b5063c633e8 (diff)
downloadcryptopp-git-ac6db2fa91744ed995bf0abcdc43e8e80491003d.tar.gz
Fix parser break on OS X
This was introduced at Commit e456cd2275bba020, and affected Uri during his rounds of testing. We also took the opportunity to write it in modern C++ (and remove the VC++ 6.0 bug workaround)
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp71
1 files changed, 20 insertions, 51 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 837db43f..fbde5313 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -659,6 +659,7 @@ void TestKeyDerivationFunction(TestData &v)
bool GetField(std::istream &is, std::string &name, std::string &value)
{
+ // ***** Name *****
name.clear();
is >> name;
@@ -678,67 +679,35 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
while (is.peek() == ' ')
is.ignore(1);
- // VC60 workaround: getline bug
- char buffer[128];
+ // ***** Value *****
value.clear();
- bool continueLine, space = false;
+ std::string line;
+ bool continueLine = true;
- do
+ while (continueLine && std::getline(is, line))
{
- continueLine = false;
- do
- {
- is.get(buffer, sizeof(buffer));
-
- // Eat leading whispace on line continuation
- if (continueLine == true)
- {
- size_t pos = 0;
- while (buffer[pos] != '\0' && buffer[pos] != ' ')
- pos++;
- value += &buffer[pos];
- }
- else
- value += buffer;
- if (buffer[0] == ' ')
- space = true;
- }
- while (buffer[0] != 0);
- is.clear();
- is.ignore();
+ // Leading, trailing and position. The leading iterator moves right, and trailing iterator
+ // moves left. When finished, the sub-string in the middle is the value for the name.
+ std::string::size_type l, t, p;
+ const std::string whitespace = " \r\n\t\v\f";
- if (!value.empty() && value[value.size()-1] == '\r')
- value.resize(value.size()-1);
+ l = line.find_first_not_of(whitespace);
+ if (l == std::string::npos) { break; }
+ t = line.find_last_not_of(whitespace);
- if (!value.empty() && value[value.size()-1] == '\\')
- {
- value.resize(value.size()-1);
+ continueLine = false;
+ if (t != std::string::npos && line[t] == '\\') {
continueLine = true;
+ t = line.find_last_not_of(whitespace, t);
}
- else
- continueLine = false;
-
- std::string::size_type i = value.find('#');
- if (i != std::string::npos)
- value.erase(i);
- }
- while (continueLine);
- // Strip intermediate spaces for some values.
- if (space && (name == "Modulus" || name == "SubgroupOrder" || name == "SubgroupGenerator" ||
- name == "PublicElement" || name == "PrivateExponent" || name == "Signature"))
- {
- std::string temp;
- temp.reserve(value.size());
-
- std::string::const_iterator it;
- for(it = value.begin(); it != value.end(); it++)
- {
- if(*it != ' ')
- temp.push_back(*it);
+ p = line.find('#', l);
+ if (p < t) {
+ t = p;
+ t = line.find_last_not_of(whitespace, t);
}
- std::swap(temp, value);
+ value += line.substr(l, t - l + 1);
}
return true;