Back to index

php5  5.3.10
Functions
collator_is_numeric.h File Reference
#include <php.h>
#include <unicode/uchar.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

zend_uchar collator_is_numeric (UChar *str, int length, long *lval, double *dval, int allow_errors)

Function Documentation

zend_uchar collator_is_numeric ( UChar str,
int  length,
long *  lval,
double *  dval,
int  allow_errors 
)

Definition at line 225 of file collator_is_numeric.c.

{
       long local_lval;
       double local_dval;
       UChar *end_ptr_long, *end_ptr_double;
       int conv_base=10;

       if (!length) {
              return 0;
       }

       /* handle hex numbers */
       if (length>=2 && str[0]=='0' && (str[1]=='x' || str[1]=='X')) {
              conv_base=16;
       }

       errno=0;
       local_lval = collator_u_strtol(str, &end_ptr_long, conv_base);
       if (errno != ERANGE) {
              if (end_ptr_long == str+length) { /* integer string */
                     if (lval) {
                            *lval = local_lval;
                     }
                     return IS_LONG;
              } else if (end_ptr_long == str && *end_ptr_long != '\0' && *str != '.' && *str != '-') { /* ignore partial string matches */
                     return 0;
              }
       } else {
              end_ptr_long = NULL;
       }

       if (conv_base == 16) { /* hex string, under UNIX strtod() messes it up */
              /* UTODO: keep compatibility with is_numeric_string() here? */
              return 0;
       }

       local_dval = collator_u_strtod(str, &end_ptr_double);
       if (local_dval == 0 && end_ptr_double == str) {
              end_ptr_double = NULL;
       } else {
              if (end_ptr_double == str+length) { /* floating point string */
                     if (!zend_finite(local_dval)) {
                            /* "inf","nan" and maybe other weird ones */
                            return 0;
                     }

                     if (dval) {
                            *dval = local_dval;
                     }
                     return IS_DOUBLE;
              }
       }

       if (!allow_errors) {
              return 0;
       }
       if (allow_errors == -1) {
              zend_error(E_NOTICE, "A non well formed numeric value encountered");
       }

       if (allow_errors) {
              if (end_ptr_double > end_ptr_long && dval) {
                     *dval = local_dval;
                     return IS_DOUBLE;
              } else if (end_ptr_long && lval) {
                     *lval = local_lval;
                     return IS_LONG;
              }
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: