mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Text Processing
- Implemented splitq, which can handle quoted and oddly-quoted string splits.
This commit is contained in:
parent
0308ee953a
commit
05b3fa0bb6
3 changed files with 59 additions and 5 deletions
50
src/text.cpp
50
src/text.cpp
|
@ -33,10 +33,10 @@
|
|||
#include <string>
|
||||
#include <strings.h>
|
||||
#include <ctype.h>
|
||||
#include "Context.h"
|
||||
#include "util.h"
|
||||
#include "text.h"
|
||||
#include "utf8.h"
|
||||
#include <Context.h>
|
||||
#include <util.h>
|
||||
#include <text.h>
|
||||
#include <utf8.h>
|
||||
|
||||
extern Context context;
|
||||
|
||||
|
@ -59,6 +59,48 @@ void wrapText (
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void splitq (
|
||||
std::vector<std::string>& results,
|
||||
const std::string& input,
|
||||
const char delimiter)
|
||||
{
|
||||
results.clear ();
|
||||
|
||||
std::string::size_type start = 0;
|
||||
std::string::size_type i = 0;
|
||||
std::string word;
|
||||
bool in_quote = false;
|
||||
char quote;
|
||||
|
||||
while (utf8_next_char (input, i))
|
||||
{
|
||||
if (in_quote)
|
||||
{
|
||||
if (input[i] == quote)
|
||||
{
|
||||
in_quote = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input[i] == delimiter)
|
||||
{
|
||||
results.push_back (unquoteText (input.substr (start, i - start)));
|
||||
start = i + 1;
|
||||
}
|
||||
else if (input[i] == '\'' ||
|
||||
input[i] == '"')
|
||||
{
|
||||
quote = input[i];
|
||||
in_quote = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
results.push_back (unquoteText (input.substr (start)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void split (
|
||||
std::vector<std::string>& results,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue