diff options
author | Jeffrey Walton <noloader@gmail.com> | 2021-03-19 18:30:11 -0400 |
---|---|---|
committer | Jeffrey Walton <noloader@gmail.com> | 2021-03-19 18:30:11 -0400 |
commit | 182fd5f100ab3d7a90cf74d3e4b63a79703471b3 (patch) | |
tree | e257818af6e9257df96e4dc9ee28f2ec982990f4 /datatest.cpp | |
parent | f69ec3c75c9f5bfe77c6b38fc9aaaade6e15d848 (diff) | |
download | cryptopp-git-182fd5f100ab3d7a90cf74d3e4b63a79703471b3.tar.gz |
Use Readline in datatest.cpp
Diffstat (limited to 'datatest.cpp')
-rw-r--r-- | datatest.cpp | 38 |
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] == '#')
|