diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | configure.ac | 6 | ||||
-rw-r--r-- | doc/pcrecpp.3 | 5 | ||||
-rw-r--r-- | pcrecpp.cc | 14 | ||||
-rw-r--r-- | pcrecpp_unittest.cc | 16 | ||||
-rw-r--r-- | pcrecpparg.h.in | 1 |
6 files changed, 44 insertions, 5 deletions
@@ -1,6 +1,13 @@ ChangeLog for PCRE ------------------ +Version 7.5 12-Nov-07 +--------------------- + +1. Applied a patch from Craig: "This patch makes it possible to 'ignore' + values in parens when parsing an RE using the C++ wrapper." + + Version 7.4 21-Sep-07 --------------------- diff --git a/configure.ac b/configure.ac index cd2dc8e..aaa4419 100644 --- a/configure.ac +++ b/configure.ac @@ -7,9 +7,9 @@ dnl be defined as -RC2, for example. For real releases, it should be defined dnl empty. m4_define(pcre_major, [7]) -m4_define(pcre_minor, [4]) -m4_define(pcre_prerelease, []) -m4_define(pcre_date, [2007-09-21]) +m4_define(pcre_minor, [5]) +m4_define(pcre_prerelease, [-RC1]) +m4_define(pcre_date, [2007-11-12]) # Libtool shared library interface versions (current:revision:age) m4_define(libpcre_version, [0:1:0]) diff --git a/doc/pcrecpp.3 b/doc/pcrecpp.3 index ee7bb78..e8f09b3 100644 --- a/doc/pcrecpp.3 +++ b/doc/pcrecpp.3 @@ -79,7 +79,8 @@ The function returns true iff all of the following conditions are satisfied: .sp c. The "i"th argument has a suitable type for holding the string captured as the "i"th sub-pattern. If you pass in - NULL for the "i"th argument, or pass fewer arguments than + void * NULL for the "i"th argument, or a non-void * NULL + of the correct type, or pass fewer arguments than the number of sub-patterns, "i"th captured sub-pattern is ignored. .sp @@ -337,5 +338,5 @@ Copyright (c) 2007 Google Inc. .rs .sp .nf -Last updated: 06 March 2007 +Last updated: 12 November 2007 .fi @@ -618,23 +618,27 @@ bool Arg::parse_null(const char* str, int n, void* dest) { } bool Arg::parse_string(const char* str, int n, void* dest) { + if (dest == NULL) return true; reinterpret_cast<string*>(dest)->assign(str, n); return true; } bool Arg::parse_stringpiece(const char* str, int n, void* dest) { + if (dest == NULL) return true; reinterpret_cast<StringPiece*>(dest)->set(str, n); return true; } bool Arg::parse_char(const char* str, int n, void* dest) { if (n != 1) return false; + if (dest == NULL) return true; *(reinterpret_cast<char*>(dest)) = str[0]; return true; } bool Arg::parse_uchar(const char* str, int n, void* dest) { if (n != 1) return false; + if (dest == NULL) return true; *(reinterpret_cast<unsigned char*>(dest)) = str[0]; return true; } @@ -683,6 +687,7 @@ bool Arg::parse_long_radix(const char* str, long r = strtol(str, &end, radix); if (end != str + n) return false; // Leftover junk if (errno) return false; + if (dest == NULL) return true; *(reinterpret_cast<long*>(dest)) = r; return true; } @@ -700,6 +705,7 @@ bool Arg::parse_ulong_radix(const char* str, unsigned long r = strtoul(str, &end, radix); if (end != str + n) return false; // Leftover junk if (errno) return false; + if (dest == NULL) return true; *(reinterpret_cast<unsigned long*>(dest)) = r; return true; } @@ -711,6 +717,7 @@ bool Arg::parse_short_radix(const char* str, long r; if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse if (r < SHRT_MIN || r > SHRT_MAX) return false; // Out of range + if (dest == NULL) return true; *(reinterpret_cast<short*>(dest)) = static_cast<short>(r); return true; } @@ -722,6 +729,7 @@ bool Arg::parse_ushort_radix(const char* str, unsigned long r; if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse if (r > USHRT_MAX) return false; // Out of range + if (dest == NULL) return true; *(reinterpret_cast<unsigned short*>(dest)) = static_cast<unsigned short>(r); return true; } @@ -733,6 +741,7 @@ bool Arg::parse_int_radix(const char* str, long r; if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse if (r < INT_MIN || r > INT_MAX) return false; // Out of range + if (dest == NULL) return true; *(reinterpret_cast<int*>(dest)) = r; return true; } @@ -744,6 +753,7 @@ bool Arg::parse_uint_radix(const char* str, unsigned long r; if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse if (r > UINT_MAX) return false; // Out of range + if (dest == NULL) return true; *(reinterpret_cast<unsigned int*>(dest)) = r; return true; } @@ -771,6 +781,7 @@ bool Arg::parse_longlong_radix(const char* str, #endif if (end != str + n) return false; // Leftover junk if (errno) return false; + if (dest == NULL) return true; *(reinterpret_cast<long long*>(dest)) = r; return true; #endif /* HAVE_LONG_LONG */ @@ -800,6 +811,7 @@ bool Arg::parse_ulonglong_radix(const char* str, #endif if (end != str + n) return false; // Leftover junk if (errno) return false; + if (dest == NULL) return true; *(reinterpret_cast<unsigned long long*>(dest)) = r; return true; #endif /* HAVE_UNSIGNED_LONG_LONG */ @@ -817,6 +829,7 @@ bool Arg::parse_double(const char* str, int n, void* dest) { double r = strtod(buf, &end); if (end != buf + n) return false; // Leftover junk if (errno) return false; + if (dest == NULL) return true; *(reinterpret_cast<double*>(dest)) = r; return true; } @@ -824,6 +837,7 @@ bool Arg::parse_double(const char* str, int n, void* dest) { bool Arg::parse_float(const char* str, int n, void* dest) { double r; if (!parse_double(str, n, &r)) return false; + if (dest == NULL) return true; *(reinterpret_cast<float*>(dest)) = static_cast<float>(r); return true; } diff --git a/pcrecpp_unittest.cc b/pcrecpp_unittest.cc index 463a11c..90351bf 100644 --- a/pcrecpp_unittest.cc +++ b/pcrecpp_unittest.cc @@ -857,6 +857,22 @@ int main(int argc, char** argv) { CHECK_EQ(s, string("ruby")); CHECK_EQ(i, 1234); + // Ignore non-void* NULL arg + CHECK(RE("he(.*)lo").FullMatch("hello", (char*)NULL)); + CHECK(RE("h(.*)o").FullMatch("hello", (string*)NULL)); + CHECK(RE("h(.*)o").FullMatch("hello", (StringPiece*)NULL)); + CHECK(RE("(.*)").FullMatch("1234", (int*)NULL)); + CHECK(RE("(.*)").FullMatch("1234567890123456", (long long*)NULL)); + CHECK(RE("(.*)").FullMatch("123.4567890123456", (double*)NULL)); + CHECK(RE("(.*)").FullMatch("123.4567890123456", (float*)NULL)); + + // Fail on non-void* NULL arg if the match doesn't parse for the given type. + CHECK(!RE("h(.*)lo").FullMatch("hello", &s, (char*)NULL)); + CHECK(!RE("(.*)").FullMatch("hello", (int*)NULL)); + CHECK(!RE("(.*)").FullMatch("1234567890123456", (int*)NULL)); + CHECK(!RE("(.*)").FullMatch("hello", (double*)NULL)); + CHECK(!RE("(.*)").FullMatch("hello", (float*)NULL)); + // Ignored arg CHECK(RE("(\\w+)(:)(\\d+)").FullMatch("ruby:1234", &s, (void*)NULL, &i)); CHECK_EQ(s, string("ruby")); diff --git a/pcrecpparg.h.in b/pcrecpparg.h.in index 83cc44b..61bcab5 100644 --- a/pcrecpparg.h.in +++ b/pcrecpparg.h.in @@ -48,6 +48,7 @@ template <class T> class _RE_MatchObject { public: static inline bool Parse(const char* str, int n, void* dest) { + if (dest == NULL) return true; T* object = reinterpret_cast<T*>(dest); return object->ParseFrom(str, n); } |