diff options
| author | Sterling Hughes <sterling@php.net> | 2003-05-23 15:11:15 +0000 |
|---|---|---|
| committer | Sterling Hughes <sterling@php.net> | 2003-05-23 15:11:15 +0000 |
| commit | ae9106521a8d5fa9c203dbdbb44888833af1436c (patch) | |
| tree | 2fe627dc09da643c5d5d4af2ce3f5cbed9fe3658 /Zend/zend_operators.c | |
| parent | b94bd055eeb163d591dc203ac26a0ed8837a70a3 (diff) | |
| download | php-git-ae9106521a8d5fa9c203dbdbb44888833af1436c.tar.gz | |
move HANDLE_NUMERIC() from the hash table implementation upstream to the
places that actually need to use it.
Diffstat (limited to 'Zend/zend_operators.c')
| -rw-r--r-- | Zend/zend_operators.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 2904eeab07..18408fed72 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -33,6 +33,41 @@ #include "ext/bcmath/number.h" #endif +ZEND_API zend_bool zend_is_numeric_key(zval *zvalue, long *val) +{ + char *tmp; + long length; + + tmp = zvalue->value.str.val; + length = zvalue->value.str.len; + + if ((*tmp>='0' && *tmp<='9')) { /* possibly a numeric index */ + char *end=tmp+length; + ulong idx; + + if (*tmp++=='0' && length>2) { /* don't accept numbers with leading zeros */ + return 0; + } + + while (tmp<end) { + if (!(*tmp>='0' && *tmp<='9')) { + break; + } + tmp++; + } + + if (tmp==end && *tmp=='\0') { /* a numeric index */ + idx = strtol(zvalue->value.str.val, NULL, 10); + if (idx!=LONG_MAX) { + *val = idx; + return 1; + } + } + } + + return 0; +} + ZEND_API int zend_atoi(const char *str, int str_len) { int retval; |
