From fb9e82ed0e7d3e1170c8cbb5cdf92eaebdd13a05 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 13 Aug 2011 23:19:11 -0400 Subject: [PATCH] TDB2 parsing - TDB2::load_lines was splitting the text on \n, but because the last line contains \n, there was an additional blank line. This is what split_minimal is for. - split_minimal contained a copy/paste bug that added the extra line if the input was non-trivial, instead of if the remainder was non- trivial. - Fixed incorrect unit test accordingly. --- src/TDB2.cpp | 8 ++------ src/text.cpp | 2 +- test/text.t.cpp | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index a979d23e9..e64a6ea13 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -25,6 +25,7 @@ // //////////////////////////////////////////////////////////////////////////////// +//#include // TODO Remove. #include #include #include @@ -287,13 +288,8 @@ void TF2::load_lines () if (! _loaded_contents) load_contents (); - split (_lines, _contents, '\n'); + split_minimal (_lines, _contents, '\n'); _loaded_lines = true; - -/* - if (_lines.back () == "") - _lines.pop_back (); -*/ } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/text.cpp b/src/text.cpp index ad4febf53..417645248 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -143,7 +143,7 @@ void split_minimal ( start = i + 1; } - if (input.length ()) + if (start < input.length ()) results.push_back (input.substr (start)); } diff --git a/test/text.t.cpp b/test/text.t.cpp index de13fb395..244785fcf 100644 --- a/test/text.t.cpp +++ b/test/text.t.cpp @@ -112,7 +112,7 @@ int main (int argc, char** argv) t.is (items[1], "", "split '-' '-' -> [1] ''"); split_minimal (items, unsplit, '-'); - t.is (items.size (), (size_t) 1, "split '-' '-' -> '-'"); + t.is (items.size (), (size_t) 0, "split '-' '-' ->"); unsplit = "-a-bc-def"; split (items, unsplit, '-');