summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2017-05-14 02:41:22 -0400
committerJeffrey Walton <noloader@gmail.com>2017-05-14 02:41:22 -0400
commit2c570e27a02bfcab2eda02b9d61cde9ef2624899 (patch)
tree9e0ab59a758cc8263a7e7a1c84625d30fcd98888 /datatest.cpp
parentbc2678478ce9bf008d3111b9414b3c05bd539213 (diff)
downloadcryptopp-git-2c570e27a02bfcab2eda02b9d61cde9ef2624899.tar.gz
Explicitly add space on line continuation
Formatting of data for a failed self test was still off a bit. It was due to retaining a whitespace character from the test vector file. The problem was, the whitespace was a tab on occasion.
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 58be70be..64065ea3 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -706,6 +706,10 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
if (line[line.size() - 1] == '\\') {
continueLine = true;
}
+ // Check for comment. It can be first character
+ if (line[0] == '#') {
+ continue;
+ }
}
// Leading, trailing and temp position. The leading position moves right, and
@@ -713,36 +717,22 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
// the name. We leave one space when line continuation is in effect, (and if
// present). The value can be an empty string. One Plaintext value is often
// empty for algorithm testing.
- std::string::size_type l, t, p;
+ std::string::size_type l=0, t=std::string::npos;
const std::string whitespace = " \r\n\t\v\f";
- l = line.find_first_not_of(whitespace);
+ l = line.find_first_not_of(whitespace, l);
if (l == std::string::npos) { l = 0; }
- t = line.find_last_not_of(whitespace+"\\");
- if (l == std::string::npos) { t = line.size(); }
-
- // Chop comment. Perform after setting continueLine
- p = line.find('#', l);
- if (p < t) {
- t = p;
- if (t) t--;
- }
+ t = line.find('#', l);
+ if (t != std::string::npos) { t--; }
- // Leave one whitespace if line continuation is in effect
- if (continueLine)
- {
- if (l > 0 && ::isspace(line[l - 1]))
- {
- l--;
- }
- else if (t < line.size()-1 && ::isspace(line[t + 1]))
- {
- t++;
- }
- }
+ t = line.find_last_not_of(whitespace+"\\", t);
+ if (t != std::string::npos) { t++; }
CRYPTOPP_ASSERT(t >= l);
- value += line.substr(l, t - l + 1);
+ value += line.substr(l, t - l);
+
+ if (continueLine)
+ value.append(1, ' ');
}
return true;