mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
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.
This commit is contained in:
parent
587f2a002f
commit
fb9e82ed0e
3 changed files with 4 additions and 8 deletions
|
@ -25,6 +25,7 @@
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//#include <iostream> // TODO Remove.
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <TDB2.h>
|
#include <TDB2.h>
|
||||||
|
@ -287,13 +288,8 @@ void TF2::load_lines ()
|
||||||
if (! _loaded_contents)
|
if (! _loaded_contents)
|
||||||
load_contents ();
|
load_contents ();
|
||||||
|
|
||||||
split (_lines, _contents, '\n');
|
split_minimal (_lines, _contents, '\n');
|
||||||
_loaded_lines = true;
|
_loaded_lines = true;
|
||||||
|
|
||||||
/*
|
|
||||||
if (_lines.back () == "")
|
|
||||||
_lines.pop_back ();
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -143,7 +143,7 @@ void split_minimal (
|
||||||
start = i + 1;
|
start = i + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.length ())
|
if (start < input.length ())
|
||||||
results.push_back (input.substr (start));
|
results.push_back (input.substr (start));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ int main (int argc, char** argv)
|
||||||
t.is (items[1], "", "split '-' '-' -> [1] ''");
|
t.is (items[1], "", "split '-' '-' -> [1] ''");
|
||||||
|
|
||||||
split_minimal (items, unsplit, '-');
|
split_minimal (items, unsplit, '-');
|
||||||
t.is (items.size (), (size_t) 1, "split '-' '-' -> '-'");
|
t.is (items.size (), (size_t) 0, "split '-' '-' ->");
|
||||||
|
|
||||||
unsplit = "-a-bc-def";
|
unsplit = "-a-bc-def";
|
||||||
split (items, unsplit, '-');
|
split (items, unsplit, '-');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue