Feature #891
- Added feature #891, which allows for leftmost partial matches of UUID values. Makes direct comparisons for full-length values, and regular expressions for partial values. Note that there is a minimum length of 8 hex digits. - Added safety parsing mechanism that fails a partial UUID if immediately followed by a hex digit. This allows for numbers longer than 8 digits to not be misinterpreted as a UUID. - Implemented Nibbler::getPartialUUID. - Implemented unit tests. @@ -1145,12 +1145,23 @@ const A3 A3::sequence (const A3& input) const for (unsigned int i = 0; i < uuids.size (); ++i) { - if (ids.size ()) + if (ids.size () + i > 0) sequenced.push_back (Arg ("or", Arg::cat_op)); - sequenced.push_back (Arg ("uuid", Arg::type_string, Arg::cat_dom)); - sequenced.push_back (Arg ("=", Arg::cat_op)); - sequenced.push_back (Arg (uuids[i], Arg::type_string, Arg::cat_literal)); + // A full-length UUID requires a string comparison. + if (uuids[i].length () == 36) + { + sequenced.push_back (Arg ("uuid", Arg::type_string, Arg::cat_dom)); + sequenced.push_back (Arg ("=", Arg::cat_op)); + sequenced.push_back (Arg (uuids[i], Arg::type_string, Arg::cat_literal)); + } + // A UUID fragment is a leftmost comparison. + else + { + sequenced.push_back (Arg ("uuid", Arg::type_string, Arg::cat_dom)); + sequenced.push_back (Arg ("~", Arg::cat_op)); + sequenced.push_back (Arg ("^" + uuids[i], Arg::type_string, Arg::cat_rx)); + } } sequenced.push_back (Arg (")", Arg::cat_op)); @@ -1674,11 +1685,11 @@ bool A3::is_uuid (Nibbler& n, std::string& result) n.save (); result = ""; std::string uuid; - if (n.getUUID (uuid)) + if (n.getPartialUUID (uuid)) { result += uuid; while (n.skip (',') && - n.getUUID (uuid)) + n.getPartialUUID (uuid)) { result += ',' + uuid; } @@ -1997,13 +2008,13 @@ bool A3::extract_uuid ( Nibbler n (input); std::string uuid; - if (n.getUUID (uuid)) + if (n.getPartialUUID (uuid)) { sequence.push_back (uuid); while (n.skip (',')) { - if (!n.getUUID (uuid)) + if (!n.getPartialUUID (uuid)) throw std::string (STRING_A3_UUID_AFTER_COMMA); sequence.push_back (uuid);
This commit is contained in:
@@ -38,7 +38,8 @@
|
||||
#include <RX.h>
|
||||
#endif
|
||||
|
||||
const char* c_digits = "0123456789"; // TODO Not used?
|
||||
static const char* _uuid_pattern = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
|
||||
static const unsigned int _uuid_min_length = 8;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Nibbler::Nibbler ()
|
||||
@@ -613,6 +614,36 @@ bool Nibbler::getUUID (std::string& result)
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool Nibbler::getPartialUUID (std::string& result)
|
||||
{
|
||||
std::string::size_type i;
|
||||
for (i = 0; i < 36 && i < (_length - _cursor); i++)
|
||||
{
|
||||
if (_uuid_pattern[i] == 'x' && !isxdigit (_input[_cursor + i]))
|
||||
break;
|
||||
|
||||
else if (_uuid_pattern[i] == '-' && _input[_cursor + i] != '-')
|
||||
break;
|
||||
}
|
||||
|
||||
// If the partial match found is long enough, consider it a match.
|
||||
if (i >= _uuid_min_length)
|
||||
{
|
||||
// Fail if there is another hex digit.
|
||||
if (_cursor + i < _length &&
|
||||
isxdigit (_input[_cursor + i]))
|
||||
return false;
|
||||
|
||||
result = _input.substr (_cursor, i);
|
||||
_cursor += i;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// 19980119T070000Z = YYYYMMDDThhmmssZ
|
||||
bool Nibbler::getDateISO (time_t& t)
|
||||
|
||||
Reference in New Issue
Block a user