33 |
#include "config.h" |
#include "config.h" |
34 |
#endif |
#endif |
35 |
|
|
|
#ifdef _WIN32 |
|
|
#define HAVE_STRTOQ 1 |
|
|
#define strtoll _strtoui64 |
|
|
#define strtoull _strtoi64 |
|
|
#endif |
|
|
|
|
36 |
#include <stdlib.h> |
#include <stdlib.h> |
37 |
#include <stdio.h> |
#include <stdio.h> |
38 |
#include <ctype.h> |
#include <ctype.h> |
331 |
|
|
332 |
// Returns PCRE_NEWLINE_CRLF, PCRE_NEWLINE_CR, or PCRE_NEWLINE_LF. |
// Returns PCRE_NEWLINE_CRLF, PCRE_NEWLINE_CR, or PCRE_NEWLINE_LF. |
333 |
// Note that PCRE_NEWLINE_CRLF is defined to be P_N_CR | P_N_LF. |
// Note that PCRE_NEWLINE_CRLF is defined to be P_N_CR | P_N_LF. |
334 |
|
// Modified by PH to add PCRE_NEWLINE_ANY and PCRE_NEWLINE_ANYCRLF. |
335 |
|
|
336 |
static int NewlineMode(int pcre_options) { |
static int NewlineMode(int pcre_options) { |
337 |
// TODO: if we can make it threadsafe, cache this var |
// TODO: if we can make it threadsafe, cache this var |
338 |
int newline_mode = 0; |
int newline_mode = 0; |
339 |
/* if (newline_mode) return newline_mode; */ // do this once it's cached |
/* if (newline_mode) return newline_mode; */ // do this once it's cached |
340 |
if (pcre_options & (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)) { |
if (pcre_options & (PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF| |
341 |
|
PCRE_NEWLINE_ANY|PCRE_NEWLINE_ANYCRLF)) { |
342 |
newline_mode = (pcre_options & |
newline_mode = (pcre_options & |
343 |
(PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF)); |
(PCRE_NEWLINE_CRLF|PCRE_NEWLINE_CR|PCRE_NEWLINE_LF| |
344 |
|
PCRE_NEWLINE_ANY|PCRE_NEWLINE_ANYCRLF)); |
345 |
} else { |
} else { |
346 |
int newline; |
int newline; |
347 |
pcre_config(PCRE_CONFIG_NEWLINE, &newline); |
pcre_config(PCRE_CONFIG_NEWLINE, &newline); |
351 |
newline_mode = PCRE_NEWLINE_CR; |
newline_mode = PCRE_NEWLINE_CR; |
352 |
else if (newline == 3338) |
else if (newline == 3338) |
353 |
newline_mode = PCRE_NEWLINE_CRLF; |
newline_mode = PCRE_NEWLINE_CRLF; |
354 |
|
else if (newline == -1) |
355 |
|
newline_mode = PCRE_NEWLINE_ANY; |
356 |
|
else if (newline == -2) |
357 |
|
newline_mode = PCRE_NEWLINE_ANYCRLF; |
358 |
else |
else |
359 |
assert("" == "Unexpected return value from pcre_config(NEWLINE)"); |
assert("" == "Unexpected return value from pcre_config(NEWLINE)"); |
360 |
} |
} |
384 |
// Note it's better to call pcre_fullinfo() than to examine |
// Note it's better to call pcre_fullinfo() than to examine |
385 |
// all_options(), since options_ could have changed bewteen |
// all_options(), since options_ could have changed bewteen |
386 |
// compile-time and now, but this is simpler and safe enough. |
// compile-time and now, but this is simpler and safe enough. |
387 |
|
// Modified by PH to add ANY and ANYCRLF. |
388 |
if (start+1 < static_cast<int>(str->length()) && |
if (start+1 < static_cast<int>(str->length()) && |
389 |
(*str)[start] == '\r' && (*str)[start+1] == '\n' && |
(*str)[start] == '\r' && (*str)[start+1] == '\n' && |
390 |
NewlineMode(options_.all_options()) == PCRE_NEWLINE_CRLF) { |
(NewlineMode(options_.all_options()) == PCRE_NEWLINE_CRLF || |
391 |
|
NewlineMode(options_.all_options()) == PCRE_NEWLINE_ANY || |
392 |
|
NewlineMode(options_.all_options()) == PCRE_NEWLINE_ANYCRLF) |
393 |
|
) { |
394 |
matchend++; |
matchend++; |
395 |
} |
} |
396 |
// We also need to advance more than one char if we're in utf8 mode. |
// We also need to advance more than one char if we're in utf8 mode. |
711 |
long r; |
long r; |
712 |
if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse |
if (!parse_long_radix(str, n, &r, radix)) return false; // Could not parse |
713 |
if (r < SHRT_MIN || r > SHRT_MAX) return false; // Out of range |
if (r < SHRT_MIN || r > SHRT_MAX) return false; // Out of range |
714 |
*(reinterpret_cast<short*>(dest)) = r; |
*(reinterpret_cast<short*>(dest)) = static_cast<short>(r); |
715 |
return true; |
return true; |
716 |
} |
} |
717 |
|
|
722 |
unsigned long r; |
unsigned long r; |
723 |
if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse |
if (!parse_ulong_radix(str, n, &r, radix)) return false; // Could not parse |
724 |
if (r > USHRT_MAX) return false; // Out of range |
if (r > USHRT_MAX) return false; // Out of range |
725 |
*(reinterpret_cast<unsigned short*>(dest)) = r; |
*(reinterpret_cast<unsigned short*>(dest)) = static_cast<unsigned short>(r); |
726 |
return true; |
return true; |
727 |
} |
} |
728 |
|
|
764 |
long long r = strtoq(str, &end, radix); |
long long r = strtoq(str, &end, radix); |
765 |
#elif defined HAVE_STRTOLL |
#elif defined HAVE_STRTOLL |
766 |
long long r = strtoll(str, &end, radix); |
long long r = strtoll(str, &end, radix); |
767 |
|
#elif defined HAVE__STRTOI64 |
768 |
|
long long r = _strtoi64(str, &end, radix); |
769 |
#else |
#else |
770 |
#error parse_longlong_radix: cannot convert input to a long-long |
#error parse_longlong_radix: cannot convert input to a long-long |
771 |
#endif |
#endif |
793 |
unsigned long long r = strtouq(str, &end, radix); |
unsigned long long r = strtouq(str, &end, radix); |
794 |
#elif defined HAVE_STRTOLL |
#elif defined HAVE_STRTOLL |
795 |
unsigned long long r = strtoull(str, &end, radix); |
unsigned long long r = strtoull(str, &end, radix); |
796 |
|
#elif defined HAVE__STRTOI64 |
797 |
|
unsigned long long r = _strtoui64(str, &end, radix); |
798 |
#else |
#else |
799 |
#error parse_ulonglong_radix: cannot convert input to a long-long |
#error parse_ulonglong_radix: cannot convert input to a long-long |
800 |
#endif |
#endif |