Variant php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { int len; const char *str, *end; char *num, *p; char dec_sep = '.'; char tsd_sep[4] = "',."; int64 lval; double dval; int first, n; Variant ret; len = in_str.size(); str = in_str.data(); PHP_FILTER_TRIM_DEFAULT(str, len); end = str + len; if (option_array.isArray()) { Array arr_options = option_array.toArray(); if (arr_options.exists("decimal")) { String decimal = arr_options["decimal"].toString(); if (decimal.size() != 1) { raise_warning("decimal separator must be one char"); RETURN_VALIDATION_FAILED }
void php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { size_t len; char *str, *end; char *num, *p; zval *option_val; char *decimal; int decimal_set; size_t decimal_len; char dec_sep = '.'; char tsd_sep[3] = "',."; zend_long lval; double dval; int first, n; len = Z_STRLEN_P(value); str = Z_STRVAL_P(value); PHP_FILTER_TRIM_DEFAULT(str, len); end = str + len; FETCH_STRING_OPTION(decimal, "decimal"); if (decimal_set) { if (decimal_len != 1) { php_error_docref(NULL, E_WARNING, "decimal separator must be one char"); RETURN_VALIDATION_FAILED } else {
Variant php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) { /* Parse options */ long min_range, max_range; int min_range_set, max_range_set; FETCH_LONG_OPTION(min_range, s_min_range); FETCH_LONG_OPTION(max_range, s_max_range); long option_flags = flags; int len = value.length(); if (len == 0) { RETURN_VALIDATION_FAILED } bool allow_octal = false, allow_hex = false; if (option_flags & k_FILTER_FLAG_ALLOW_OCTAL) { allow_octal = true; } if (option_flags & k_FILTER_FLAG_ALLOW_HEX) { allow_hex = true; } /* Start the validating loop */ const char *p = value.data(); long ctx_value = 0; PHP_FILTER_TRIM_DEFAULT(p, len); int error = 0; if (*p == '0') { p++; len--; if (allow_hex && (*p == 'x' || *p == 'X')) { p++; len--; if (php_filter_parse_hex(p, len, &ctx_value) < 0) { assert(ctx_value == 0); error = 1; } } else if (allow_octal) { if (php_filter_parse_octal(p, len, &ctx_value) < 0) { assert(ctx_value == 0); error = 1; } } else if (len != 0) { error = 1; } } else { if (php_filter_parse_int(p, len, &ctx_value) < 0) { assert(ctx_value == 0); error = 1; } } if (error > 0 || (min_range_set && (ctx_value < min_range)) || (max_range_set && (ctx_value > max_range))) { RETURN_VALIDATION_FAILED } else { return ctx_value; } }
Variant php_filter_float(PHP_INPUT_FILTER_PARAM_DECL) { char dec_sep = '.'; char tsd_sep[3] = {'\'', ',', '.'}; int len = value.length(); const char *str = value.data(); PHP_FILTER_TRIM_DEFAULT(str, len); const char *end = str + len; const char *decimal; int decimal_set, decimal_len; FETCH_STRING_OPTION(decimal, s_decimal); if (decimal_set) { if (decimal_len != 1) { raise_warning("decimal separator must be one char"); RETURN_VALIDATION_FAILED } else {
void php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { zval *option_val; zend_long min_range, max_range, option_flags; int min_range_set, max_range_set; int allow_octal = 0, allow_hex = 0; size_t len; int error = 0; zend_long ctx_value; char *p; /* Parse options */ FETCH_LONG_OPTION(min_range, "min_range"); FETCH_LONG_OPTION(max_range, "max_range"); option_flags = flags; len = Z_STRLEN_P(value); if (len == 0) { RETURN_VALIDATION_FAILED } if (option_flags & FILTER_FLAG_ALLOW_OCTAL) { allow_octal = 1; } if (option_flags & FILTER_FLAG_ALLOW_HEX) { allow_hex = 1; } /* Start the validating loop */ p = Z_STRVAL_P(value); ctx_value = 0; PHP_FILTER_TRIM_DEFAULT(p, len); if (*p == '0') { p++; len--; if (allow_hex && (*p == 'x' || *p == 'X')) { p++; len--; if (php_filter_parse_hex(p, len, &ctx_value) < 0) { error = 1; } } else if (allow_octal) { if (php_filter_parse_octal(p, len, &ctx_value) < 0) { error = 1; } } else if (len != 0) { error = 1; } } else { if (php_filter_parse_int(p, len, &ctx_value) < 0) { error = 1; } } if (error > 0 || (min_range_set && (ctx_value < min_range)) || (max_range_set && (ctx_value > max_range))) { RETURN_VALIDATION_FAILED } else { zval_ptr_dtor(value); ZVAL_LONG(value, ctx_value); return; } }
Variant php_filter_boolean(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { const char *str = in_str.data(); int len = in_str.size(); int ret; PHP_FILTER_TRIM_DEFAULT(str, len); /* returns true for "1", "true", "on" and "yes" * returns false for "0", "false", "off", "no", and "" * null otherwise. */ switch (len) { case 1: if (*str == '1') { ret = 1; } else if (*str == '0') { ret = 0; } else { ret = -1; } break; case 2: if (strncasecmp(str, "on", 2) == 0) { ret = 1; } else if (strncasecmp(str, "no", 2) == 0) { ret = 0; } else { ret = -1; } break; case 3: if (strncasecmp(str, "yes", 3) == 0) { ret = 1; } else if (strncasecmp(str, "off", 3) == 0) { ret = 0; } else { ret = -1; } break; case 4: if (strncasecmp(str, "true", 4) == 0) { ret = 1; } else { ret = -1; } break; case 5: if (strncasecmp(str, "false", 5) == 0) { ret = 0; } else { ret = -1; } break; default: ret = -1; } if (ret == -1) { RETURN_VALIDATION_FAILED } else { return (bool) ret; } }
Variant php_filter_int(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */ { long min_range = 0, max_range = 0; int min_range_set = 0, max_range_set = 0; int allow_octal = 0, allow_hex = 0; int len, error = 0; long ctx_value; const char *p; /* Parse options */ if (option_array.isArray()) { Array arr_options = option_array.toArray(); if (arr_options.exists("min_range")) { min_range_set = 1; min_range = arr_options["min_range"].toInt64(); } if (arr_options.exists("max_range")) { max_range_set = 1; max_range = arr_options["max_range"].toInt64(); } } if (in_str.empty()) { RETURN_VALIDATION_FAILED } allow_octal = flags & FILTER_FLAG_ALLOW_OCTAL; allow_hex = flags & FILTER_FLAG_ALLOW_HEX; /* Start the validating loop */ p = in_str.data(); len = in_str.size(); ctx_value = 0; PHP_FILTER_TRIM_DEFAULT(p, len); if (*p == '0') { p++; len--; if (allow_hex && (*p == 'x' || *p == 'X')) { p++; len--; if (php_filter_parse_hex(p, len, &ctx_value) < 0) { error = 1; } } else if (allow_octal) { if (php_filter_parse_octal(p, len, &ctx_value) < 0) { error = 1; } } else if (len != 0) { error = 1; } } else { if (php_filter_parse_int(p, len, &ctx_value) < 0) { error = 1; } } if (error > 0 || (min_range_set && (ctx_value < min_range)) || (max_range_set && (ctx_value > max_range))) { RETURN_VALIDATION_FAILED } else { return ctx_value; } }