size_t i, j;
result = (char *) emalloc(oldlen * 2 * sizeof(char) + 1);
- if(!result) {
+ if (!result) {
return result;
}
- for(i = j = 0; i < oldlen; i++) {
+ for (i = j = 0; i < oldlen; i++) {
result[j++] = hexconvtab[old[i] >> 4];
result[j++] = hexconvtab[old[i] & 15];
}
int result = SUCCESS;
memset(mask, 0, 256);
- for (end=input+len; input<end; input++) {
+ for (end = input+len; input < end; input++) {
c=*input;
- if (input+3<end && input[1] == '.' && input[2] == '.'
+ if ((input+3 < end) && input[1] == '.' && input[2] == '.'
&& input[3] >= c) {
memset(mask+c, 1, input[3] - c + 1);
input+=3;
- } else if (input+1<end && input[0] == '.' && input[1] == '.') {
+ } else if ((input+1 < end) && input[0] == '.' && input[1] == '.') {
/* Error, try to be as helpful as possible:
(a range ending/starting with '.' won't be captured here) */
- if (end-len>=input) { /* there was no 'left' char */
+ if (end-len >= input) { /* there was no 'left' char */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '..'-range, no character to the left of '..'.");
result = FAILURE;
continue;
}
- if (input+2>=end) { /* there is no 'right' char */
+ if (input+2 >= end) { /* there is no 'right' char */
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid '..'-range, no character to the right of '..'.");
result = FAILURE;
continue;
c = s;
e = c+len;
- while (c<e) {
+ while (c < e) {
*c = toupper(*c);
c++;
}
c = s;
e = c+len;
- while (c<e) {
+ while (c < e) {
*c = tolower(*c);
c++;
}
c = s + len - 1;
/* do suffix removal as the unix command does */
- if(suffix && (len > sufflen)) {
- if(!strncmp(suffix, c-sufflen+1, sufflen)) {
+ if (suffix && (len > sufflen)) {
+ if (!strncmp(suffix, c-sufflen+1, sufflen)) {
c -= sufflen;
buf2 = *(c + 1); /* Save overwritten char */
*(c + 1) = '\0'; /* overwrite char */
#endif
)
c--;
- if(c < s+len-1) {
+ if (c < s+len-1) {
buf = *(c + 1); /* Save overwritten char */
*(c + 1) = '\0'; /* overwrite char */
p = c + 1; /* Save pointer to overwritten char */
} else {
ret = estrdup(s);
}
- if(buf) *p = buf;
- if(buf2) *p2 = buf2;
+ if (buf) *p = buf;
+ if (buf2) *p2 = buf2;
return (ret);
}
/* }}} */
dest = emalloc((srclen + (chunks + 1) * endlen + 1) * sizeof(char));
- for(p = src, q = dest; p < (src + srclen - chunklen + 1); ) {
+ for (p = src, q = dest; p < (src + srclen - chunklen + 1); ) {
memcpy(q, p, chunklen);
q += chunklen;
memcpy(q, end, endlen);
p += chunklen;
}
- if(restlen) {
+ if (restlen) {
memcpy(q, p, restlen);
q += restlen;
memcpy(q, end, endlen);
RETURN_FALSE;
}
- if((f + l) > Z_STRLEN_PP(str)) {
+ if ((f + l) > Z_STRLEN_PP(str)) {
l = Z_STRLEN_PP(str) - f;
}
str = emalloc(2 * Z_STRLEN_PP(arg) + 1);
- for(p = old, q = str; p != old_end; p++) {
+ for (p = old, q = str; p != old_end; p++) {
c = *p;
- switch(c) {
+ switch (c) {
case '.':
case '\\':
case '+':
convert_to_string_ex(str);
/* shortcut for empty string */
- if(Z_STRLEN_PP(str) == 0) {
+ if (Z_STRLEN_PP(str) == 0) {
RETURN_EMPTY_STRING();
}
int i, len;
char c;
- if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str)==FAILURE) {
+ if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &str) == FAILURE) {
WRONG_PARAM_COUNT;
}
convert_to_string_ex(str);
if (PG(magic_quotes_sybase)) {
while (l > 0) {
- if(*t=='\'') {
- if((l>0) && (t[1]=='\'')) {
+ if (*t == '\'') {
+ if ((l > 0) && (t[1] == '\'')) {
t++;
if (len != NULL)
(*len)--;
l--;
}
*s++ = *t++;
- } else if (*t=='\\' && l>0 && t[1]=='0') {
+ } else if (*t == '\\' && l > 0 && t[1] == '0') {
*s++='\0';
t += 2;
if (len != NULL)
(*len)--;
l--;
if (l > 0) {
- if(*t=='0') {
+ if (*t == '0') {
*s++='\0';
t++;
} else {
int nlen = *len, i;
char numtmp[4];
- for (source=str, end=str+nlen, target=str; source<end; source++) {
- if (*source == '\\' && source+1<end) {
+ for (source=str, end=str+nlen, target=str; source < end; source++) {
+ if (*source == '\\' && source+1 < end) {
source++;
switch (*source) {
case 'n': *target++='\n'; nlen--; break;
case 'b': *target++='\b'; nlen--; break;
case 'f': *target++='\f'; nlen--; break;
case '\\': *target++='\\'; nlen--; break;
- case 'x': if (source+1<end && isxdigit((int)(*(source+1)))) {
+ case 'x': if (source+1 < end && isxdigit((int)(*(source+1)))) {
numtmp[0] = *++source;
- if (source+1<end && isxdigit((int)(*(source+1)))) {
+ if (source+1 < end && isxdigit((int)(*(source+1)))) {
numtmp[1] = *++source;
numtmp[2] = '\0';
nlen-=3;
}
/* break is left intentionally */
default: i=0;
- while (source<end && *source>='0' && *source<='7' && i<3) {
+ while (source < end && *source >= '0' && *source <= '7' && i<3) {
numtmp[i++] = *source++;
}
if (i) {
}
}
- if(nlen != 0) {
+ if (nlen != 0) {
*target='\0';
}
php_charmask(what, wlength, flags TSRMLS_CC);
- for (source=str, end=source+length, target=new_str; (c=*source) || source<end; source++) {
+ for (source = str, end = source+length, target = new_str; (c=*source) || (source < end); source++) {
if (flags[(unsigned char)c]) {
if ((unsigned char)c<32 || (unsigned char)c>126) {
*target++ = '\\';
}
*target = 0;
newlen = target-new_str;
- if (target-new_str<length*4) {
+ if (target-new_str < length*4) {
new_str = erealloc(new_str, newlen+1);
}
if (new_length) {
}
new_str = (char *) emalloc((length?length:(length=strlen(str)))*2+1);
if (PG(magic_quotes_sybase)) {
- for (source=str, end=source+length, target=new_str; source<end; source++) {
+ for (source = str, end = source+length, target = new_str; source < end; source++) {
c = *source;
- switch(c) {
+ switch (c) {
case '\0':
*target++ = '\\';
*target++ = '0';
}
}
else {
- for (source=str, end=source+length, target=new_str; source<end; source++) {
+ for (source = str, end = source+length, target = new_str; source < end; source++) {
c = *source;
- switch(c) {
+ switch (c) {
case '\0':
*target++ = '\\';
*target++ = '0';
int replaced = 0;
char *source, *target, *tmp, *source_end=str+len, *tmp_end = NULL;
- for (source=str; source<source_end; source++) {
- if (*source==from) {
+ for (source = str; source < source_end; source++) {
+ if (*source == from) {
char_count++;
}
}
- if (char_count==0) {
+ if (char_count == 0) {
ZVAL_STRINGL(result, str, len, 1);
return 0;
}
while (zend_hash_get_current_data(Z_ARRVAL_P(search), (void **) &search_entry) == SUCCESS) {
/* Make sure we're dealing with strings. */
convert_to_string_ex(search_entry);
- if(Z_STRLEN_PP(search_entry) == 0) {
+ if (Z_STRLEN_PP(search_entry) == 0) {
zend_hash_move_forward(Z_ARRVAL_P(search));
continue;
}
}
}
- if(Z_STRLEN_PP(search_entry) == 1) {
+ if (Z_STRLEN_PP(search_entry) == 1) {
php_char_to_str(Z_STRVAL_P(result),
Z_STRLEN_P(result),
Z_STRVAL_PP(search_entry)[0],
ulong num_key;
int boyer = 0;
- if(ZEND_NUM_ARGS() < 3 ||
+ if (ZEND_NUM_ARGS() < 3 ||
ZEND_NUM_ARGS() > 4 ||
zend_get_parameters_ex(ZEND_NUM_ARGS(), &search,
&replace, &subject, &pboyer) == FAILURE) {
MAKE_STD_ZVAL(result);
php_str_replace_in_subject(*search, *replace, subject_entry, result, boyer);
/* Add to return array */
- switch(zend_hash_get_current_key_ex(Z_ARRVAL_PP(subject), &string_key,
+ switch (zend_hash_get_current_key_ex(Z_ARRVAL_PP(subject), &string_key,
&string_key_len, &num_key, 0, NULL)) {
case HASH_KEY_IS_STRING:
add_assoc_zval_ex(return_value, string_key, string_key_len, result);
int begin, end, char_count, orig_begin;
- switch(ZEND_NUM_ARGS()) {
+ switch (ZEND_NUM_ARGS()) {
case 1:
- if (zend_get_parameters_ex(1, &str)==FAILURE) {
+ if (zend_get_parameters_ex(1, &str) == FAILURE) {
RETURN_FALSE;
}
break;
case 2:
- if (zend_get_parameters_ex(2, &str, &max_chars_per_line)==FAILURE) {
+ if (zend_get_parameters_ex(2, &str, &max_chars_per_line) == FAILURE) {
RETURN_FALSE;
}
convert_to_long_ex(max_chars_per_line);
convert_to_string_ex(str);
- if (Z_STRLEN_PP(str)==0) {
+ if (Z_STRLEN_PP(str) == 0) {
RETURN_FALSE;
}
}
do {
- if (block_type==_HEB_BLOCK_TYPE_HEB) {
- while((isheb((int)*(tmp+1)) || _isblank((int)*(tmp+1)) || ispunct((int)*(tmp+1)) || (int)*(tmp+1)=='\n' ) && block_end<Z_STRLEN_PP(str)-1) {
+ if (block_type == _HEB_BLOCK_TYPE_HEB) {
+ while ((isheb((int)*(tmp+1)) || _isblank((int)*(tmp+1)) || ispunct((int)*(tmp+1)) || (int)*(tmp+1)=='\n' ) && block_end<Z_STRLEN_PP(str)-1) {
tmp++;
block_end++;
block_length++;
}
- for (i=block_start; i<=block_end; i++) {
+ for (i = block_start; i<= block_end; i++) {
*target = Z_STRVAL_PP(str)[i];
switch (*target) {
case '(':
}
block_type = _HEB_BLOCK_TYPE_ENG;
} else {
- while(!isheb(*(tmp+1)) && (int)*(tmp+1)!='\n' && block_end<Z_STRLEN_PP(str)-1) {
+ while (!isheb(*(tmp+1)) && (int)*(tmp+1)!='\n' && block_end < Z_STRLEN_PP(str)-1) {
tmp++;
block_end++;
block_length++;
}
- while ((_isblank((int)*tmp) || ispunct((int)*tmp)) && *tmp!='/' && *tmp!='-' && block_end>block_start) {
+ while ((_isblank((int)*tmp) || ispunct((int)*tmp)) && *tmp!='/' && *tmp!='-' && block_end > block_start) {
tmp--;
block_end--;
}
- for (i=block_end; i>=block_start; i--) {
+ for (i = block_end; i >= block_start; i--) {
*target = Z_STRVAL_PP(str)[i];
target--;
}
block_type = _HEB_BLOCK_TYPE_HEB;
}
block_start=block_end+1;
- } while(block_end<Z_STRLEN_PP(str)-1);
+ } while (block_end < Z_STRLEN_PP(str)-1);
broken_str = (char *) emalloc(Z_STRLEN_PP(str)+1);
while (1) {
char_count=0;
- while ((!max_chars || char_count<max_chars) && begin>0) {
+ while ((!max_chars || char_count < max_chars) && begin > 0) {
char_count++;
begin--;
- if (begin<=0 || _isnewline(heb_str[begin])) {
- while(begin>0 && _isnewline(heb_str[begin-1])) {
+ if (begin <= 0 || _isnewline(heb_str[begin])) {
+ while (begin > 0 && _isnewline(heb_str[begin-1])) {
begin--;
char_count++;
}
break;
}
}
- if (char_count==max_chars) { /* try to avoid breaking words */
+ if (char_count == max_chars) { /* try to avoid breaking words */
int new_char_count=char_count, new_begin=begin;
- while (new_char_count>0) {
+ while (new_char_count > 0) {
if (_isblank(heb_str[new_begin]) || _isnewline(heb_str[new_begin])) {
break;
}
new_begin++;
new_char_count--;
}
- if (new_char_count>0) {
+ if (new_char_count > 0) {
char_count=new_char_count;
begin=new_begin;
}
if (_isblank(heb_str[begin])) {
heb_str[begin]='\n';
}
- while (begin<=end && _isnewline(heb_str[begin])) { /* skip leading newlines */
+ while (begin <= end && _isnewline(heb_str[begin])) { /* skip leading newlines */
begin++;
}
- for (i=begin; i<=end; i++) { /* copy content */
+ for (i = begin; i <= end; i++) { /* copy content */
*target = heb_str[i];
target++;
}
- for (i=orig_begin; i<=end && _isnewline(heb_str[i]); i++) {
+ for (i = orig_begin; i <= end && _isnewline(heb_str[i]); i++) {
*target = heb_str[i];
target++;
}
begin=orig_begin;
- if (begin<=0) {
+ if (begin <= 0) {
*target = 0;
break;
}
char *allowed_tags=NULL;
int allowed_tags_len=0;
- switch(ZEND_NUM_ARGS()) {
+ switch (ZEND_NUM_ARGS()) {
case 1:
- if(zend_get_parameters_ex(1, &str)==FAILURE) {
+ if (zend_get_parameters_ex(1, &str) == FAILURE) {
RETURN_FALSE;
}
break;
case 2:
- if(zend_get_parameters_ex(2, &str, &allow)==FAILURE) {
+ if (zend_get_parameters_ex(2, &str, &allow) == FAILURE) {
RETURN_FALSE;
}
convert_to_string_ex(allow);
int i, cat, n_args=ZEND_NUM_ARGS();
char *loc, *retval;
- if (zend_get_parameters_array_ex(n_args, args)==FAILURE || n_args<2) {
+ if (zend_get_parameters_array_ex(n_args, args) == FAILURE || n_args < 2) {
efree(args);
WRONG_PARAM_COUNT;
}
} else {
i=1;
}
- while(1) {
+ while (1) {
if (Z_TYPE_PP(args[1]) == IS_ARRAY) {
zend_hash_get_current_data(Z_ARRVAL_PP(args[1]),(void **)&plocale);
} else {
if (Z_TYPE_PP(args[1]) == IS_ARRAY) {
zend_hash_move_forward(Z_ARRVAL_PP(args[1]));
} else {
- if(++i >= n_args) break;
+ if (++i >= n_args) break;
}
}
int old_rg;
argCount = ARG_COUNT(ht);
- if(argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg) == FAILURE) {
+ if (argCount < 1 || argCount > 2 || zend_get_parameters_ex(argCount, &arg, &arrayArg) == FAILURE) {
WRONG_PARAM_COUNT;
}
}
old_rg = PG(register_globals);
- if(argCount == 1) {
+ if (argCount == 1) {
PG(register_globals) = 1;
sapi_module.treat_data(PARSE_STRING, res, NULL TSRMLS_CC);
} else {
if (!len) {
return 0;
}
- while(!done) {
- switch(c) {
- case '<':
- *(n++) = c;
- break;
- case '>':
- done =1;
- break;
- default:
- if(!isspace((int)c)) {
- if(state==0) {
- state=1;
- if(c!='/') *(n++) = c;
+ while (!done) {
+ switch (c) {
+ case '<':
+ *(n++) = c;
+ break;
+ case '>':
+ done =1;
+ break;
+ default:
+ if (!isspace((int)c)) {
+ if (state == 0) {
+ state=1;
+ if (c != '/')
+ *(n++) = c;
+ } else {
+ *(n++) = c;
+ }
} else {
- *(n++) = c;
+ if (state == 1)
+ done=1;
}
- } else {
- if(state==1) done=1;
- }
- break;
+ break;
}
c = tolower(*(++t));
}
*(n++) = '>';
*n = '\0';
- if(strstr(set, norm)) {
+ if (strstr(set, norm)) {
done=1;
} else {
done=0;
p = buf;
rp = rbuf;
br = 0;
- if(allow) {
+ if (allow) {
php_strtolower(allow, allow_len);
tbuf = emalloc(PHP_TAG_BUF_SIZE+1);
tp = tbuf;
tbuf = tp = NULL;
}
- while(i<len) {
+ while (i < len) {
switch (c) {
case '<':
if (state == 0) {
lc = '<';
state = 1;
- if(allow) {
+ if (allow) {
*(tp++) = '<';
}
} else if (state == 1) {
case 1: /* HTML/XML */
lc = '>';
state = 0;
- if(allow) {
+ if (allow) {
*(tp++) = '>';
*tp='\0';
- if(php_tag_find(tbuf, tp-tbuf, allow)) {
+ if (php_tag_find(tbuf, tp-tbuf, allow)) {
memcpy(rp, tbuf, tp-tbuf);
rp += tp-tbuf;
}
break;
case 2: /* PHP */
- if (!br && lc != '\"' && *(p-1)=='?') {
+ if (!br && lc != '\"' && *(p-1) == '?') {
state = 0;
tp = tbuf;
}
case '?':
- if (state==1 && *(p-1)=='<') {
+ if (state == 1 && *(p-1)=='<') {
br=0;
state=2;
break;
* state == 2 (PHP). Switch back to HTML.
*/
- if(state == 2 && *(p-1) == 'm' && *(p-2) == 'x') {
+ if (state == 2 && *(p-1) == 'm' && *(p-2) == 'x') {
state = 1;
break;
}
default:
if (state == 0) {
*(rp++) = c;
- } else if(allow && state == 1) {
+ } else if (allow && state == 1) {
*(tp++) = c;
- if( (tp-tbuf)>=PHP_TAG_BUF_SIZE ) { /* no buffer overflows */
+ if ( (tp-tbuf) >= PHP_TAG_BUF_SIZE ) { /* no buffer overflows */
tp = tbuf;
}
}
}
*rp = '\0';
efree(buf);
- if(allow) efree(tbuf);
+ if (allow)
+ efree(tbuf);
if (stateptr)
*stateptr = state;
}
result = (char *)emalloc(result_len + 1);
/* Copy the input string into the result as many times as necessary */
- for (i=0; i<Z_LVAL_PP(mult); i++) {
+ for (i = 0; i < Z_LVAL_PP(mult); i++) {
memcpy(result + Z_STRLEN_PP(input_str) * i,
Z_STRVAL_PP(input_str),
Z_STRLEN_PP(input_str));
array_init(return_value);
}
- for (inx=0; inx < 256; inx++) {
+ for (inx = 0; inx < 256; inx++) {
switch (mymode) {
case 0:
add_index_long(return_value, inx, chars[inx]);
/* Grab the grouping data out of the array */
len = strlen(currlocdata.grouping);
- for (i=0;i<len;i++) {
+ for (i = 0; i < len; i++) {
add_index_long(grouping, i, currlocdata.grouping[i]);
}
/* Grab the monetary grouping data out of the array */
len = strlen(currlocdata.mon_grouping);
- for (i=0;i<len;i++) {
+ for (i = 0; i < len; i++) {
add_index_long(mon_grouping, i, currlocdata.mon_grouping[i]);
}
p = Z_STRVAL_PP(haystack);
endp = p + Z_STRLEN_PP(haystack);
while (p <= endp) {
- if( (p = php_memnstr(p, Z_STRVAL_PP(needle), Z_STRLEN_PP(needle), endp)) != NULL ) {
+ if ( (p = php_memnstr(p, Z_STRVAL_PP(needle), Z_STRLEN_PP(needle), endp)) != NULL ) {
p += Z_STRLEN_PP(needle);
count++;
} else {