summaryrefslogtreecommitdiff
path: root/datatest.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2021-03-19 18:30:11 -0400
committerJeffrey Walton <noloader@gmail.com>2021-03-19 18:30:11 -0400
commit182fd5f100ab3d7a90cf74d3e4b63a79703471b3 (patch)
treee257818af6e9257df96e4dc9ee28f2ec982990f4 /datatest.cpp
parentf69ec3c75c9f5bfe77c6b38fc9aaaade6e15d848 (diff)
downloadcryptopp-git-182fd5f100ab3d7a90cf74d3e4b63a79703471b3.tar.gz
Use Readline in datatest.cpp
Diffstat (limited to 'datatest.cpp')
-rw-r--r--datatest.cpp38
1 files changed, 37 insertions, 1 deletions
diff --git a/datatest.cpp b/datatest.cpp
index 70bdd546..6417d38c 100644
--- a/datatest.cpp
+++ b/datatest.cpp
@@ -55,6 +55,42 @@ public:
const TestData *s_currentTestData = NULLPTR;
+// Handles CR, LF, and CRLF properly
+bool Readline(std::istream& stream, std::string& line)
+{
+ line.clear();
+ line.reserve(64);
+
+ while (stream.good())
+ {
+ int ch = stream.get();
+ if (ch == '\r')
+ {
+ int next = stream.peek();
+ if (next == '\n')
+ (void)stream.get();
+
+ break;
+ }
+
+ else if (ch == '\n')
+ {
+ break;
+ }
+
+ // Grow by 1.5x as needed
+ if (line.capacity() == 0)
+ line.reserve(line.size()*3/2);
+
+ line.push_back(static_cast<char>(ch));
+ }
+
+ // Non-binding shrink to fit
+ line.reserve(0);
+
+ return stream.good();
+}
+
std::string TrimSpace(const std::string& str)
{
if (str.empty()) return "";
@@ -1076,7 +1112,7 @@ bool GetField(std::istream &is, std::string &name, std::string &value)
name.clear(); value.clear();
// ***** Name *****
- while (is >> std::ws && std::getline(is, line))
+ while (Readline(is, line))
{
// Eat whitespace and comments gracefully
if (line.empty() || line[0] == '#')