PHPAPI void php_trim2(zval **str, zval **what, zval *return_value, int mode TSRMLS_DC);
PHPAPI void php_strip_tags(char *rbuf, int len, int state, char *allow, int allow_len);
-PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result);
+PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, pval *result);
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value);
PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit);
/* {{{ php_char_to_str
*/
-PHPAPI void php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result)
+PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int to_len, zval *result)
{
- int char_count=0;
- char *source, *target, *tmp, *source_end=str+len, *tmp_end=NULL;
+ int char_count = 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) {
if (char_count==0) {
ZVAL_STRINGL(result, str, len, 1);
- return;
+ return 0;
}
Z_STRLEN_P(result) = len + (char_count * (to_len - 1));
for (source = str; source < source_end; source++) {
if (*source == from) {
+ replaced = 1;
for (tmp = to, tmp_end = tmp+to_len; tmp < tmp_end; tmp++) {
*target = *tmp;
target++;
}
}
*target = 0;
+ return replaced;
}
/* }}} */
if (new_length != (*str)->value.str.len)
RETURN_STRINGL (tmp, new_length, 0);
efree (tmp);
- /* Mac style line-endings */
- tmp = boyer_str_to_str((*str)->value.str.val, (*str)->value.str.len, "\n\r", 2, "<br />\n\r", 8, &new_length);
- if (new_length != (*str)->value.str.len)
- RETURN_STRINGL (tmp, new_length, 0);
- efree (tmp);
- /* Unix style line-endings */
- php_char_to_str((*str)->value.str.val,(*str)->value.str.len, '\n',"<br />\n", 7, return_value);
+
+ /* Mac / Unix style line-endings */
+ if (php_char_to_str((*str)->value.str.val,(*str)->value.str.len, '\n',"<br />\n", 7, return_value))
+ return;
+ efree (Z_STRVAL_P(return_value));
+ php_char_to_str((*str)->value.str.val,(*str)->value.str.len, '\r',"<br />\r", 7, return_value);
}
/* }}} */
* tab-width: 4
* c-basic-offset: 4
* End:
- * vim600: noet sw=4 ts=4 tw=78 fdm=marker
- * vim<600: noet sw=4 ts=4 tw=78
+ * vim600: noet sw=4 ts=4 fdm=marker
+ * vim<600: noet sw=4 ts=4
*/