mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Parsing
- Integrated modified Nibbler and test code from kronisk. These changes make both test and Nibbler standalone objects, with configurable features.
This commit is contained in:
parent
a262d41828
commit
fb38dca1db
4 changed files with 74 additions and 12 deletions
|
@ -25,20 +25,20 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#define L10N // Localization complete.
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <inttypes.h>
|
||||
#include <Nibbler.h>
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
#include <Date.h>
|
||||
#include <text.h>
|
||||
#endif
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
#include <RX.h>
|
||||
#endif
|
||||
|
||||
const char* c_digits = "0123456789";
|
||||
const char* c_digits = "0123456789"; // TODO Not used?
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Nibbler::Nibbler ()
|
||||
|
@ -139,6 +139,7 @@ bool Nibbler::getUntil (const std::string& terminator, std::string& result)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
bool Nibbler::getUntilRx (const std::string& regex, std::string& result)
|
||||
{
|
||||
if (_cursor < _length)
|
||||
|
@ -162,6 +163,7 @@ bool Nibbler::getUntilRx (const std::string& regex, std::string& result)
|
|||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Nibbler::getUntilOneOf (const std::string& chars, std::string& result)
|
||||
|
@ -529,6 +531,7 @@ bool Nibbler::getLiteral (const std::string& literal)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
bool Nibbler::getRx (const std::string& regex, std::string& result)
|
||||
{
|
||||
if (_cursor < _length)
|
||||
|
@ -553,6 +556,7 @@ bool Nibbler::getRx (const std::string& regex, std::string& result)
|
|||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Nibbler::getUUID (std::string& result)
|
||||
|
@ -685,6 +689,7 @@ bool Nibbler::getDateISO (time_t& t)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
bool Nibbler::getDate (const std::string& format, time_t& t)
|
||||
{
|
||||
std::string::size_type i = _cursor;
|
||||
|
@ -989,6 +994,7 @@ bool Nibbler::getDate (const std::string& format, time_t& t)
|
|||
_cursor = i;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Assumes that the options are sorted by decreasing length, so that if the
|
||||
|
@ -1120,6 +1126,7 @@ bool Nibbler::skipWS ()
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
bool Nibbler::skipRx (const std::string& regex)
|
||||
{
|
||||
if (_cursor < _length)
|
||||
|
@ -1143,6 +1150,7 @@ bool Nibbler::skipRx (const std::string& regex)
|
|||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Nibbler::skipAllOneOf (const std::string& chars)
|
||||
|
@ -1219,6 +1227,21 @@ bool Nibbler::depleted ()
|
|||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Override of ispunct, that considers #, $ and @ not to be punctuation.
|
||||
//
|
||||
// ispunct: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
|
||||
// Punctuation: ! " % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ ` { | } ~
|
||||
// delta: # $ @
|
||||
//
|
||||
bool Nibbler::isPunctuation (char c)
|
||||
{
|
||||
if (c == '@' || c == '#' || c == '$')
|
||||
return false;
|
||||
|
||||
return ispunct (c);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Nibbler::dump ()
|
||||
{
|
||||
|
|
|
@ -29,6 +29,12 @@
|
|||
#define INCLUDED_NIBBLER
|
||||
#define L10N // Localization complete.
|
||||
|
||||
#define NIBBLER_FEATURE_DATE
|
||||
//#undef NIBBLER_FEATURE_DATE
|
||||
|
||||
#define NIBBLER_FEATURE_REGEX
|
||||
//#undef NIBBLER_FEATURE_REGEX
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -44,7 +50,9 @@ public:
|
|||
|
||||
bool getUntil (char, std::string&);
|
||||
bool getUntil (const std::string&, std::string&);
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
bool getUntilRx (const std::string&, std::string&);
|
||||
#endif
|
||||
bool getUntilOneOf (const std::string&, std::string&);
|
||||
bool getUntilWS (std::string&);
|
||||
bool getUntilEOL (std::string&);
|
||||
|
@ -64,10 +72,14 @@ public:
|
|||
bool getNumber (double&);
|
||||
bool getUnsignedNumber (double&);
|
||||
bool getLiteral (const std::string&);
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
bool getRx (const std::string&, std::string&);
|
||||
#endif
|
||||
bool getUUID (std::string&);
|
||||
bool getDateISO (time_t&);
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
bool getDate (const std::string&, time_t&);
|
||||
#endif
|
||||
bool getOneOf (const std::vector <std::string>&, std::string&);
|
||||
bool getName (std::string&);
|
||||
bool getWord (std::string&);
|
||||
|
@ -77,7 +89,9 @@ public:
|
|||
bool skipAll (char);
|
||||
bool skipAllOneOf (const std::string&);
|
||||
bool skipWS ();
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
bool skipRx (const std::string&);
|
||||
#endif
|
||||
|
||||
char next ();
|
||||
std::string next (const int quantity);
|
||||
|
@ -89,6 +103,7 @@ public:
|
|||
|
||||
bool depleted ();
|
||||
|
||||
static bool isPunctuation (char);
|
||||
std::string dump ();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue