no response, so i noticed that i forgot to cc: the dev list. b. ----- Original Message ----- From: "Boian Bonev" <[EMAIL PROTECTED]> To: "Derick Rethans" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Sunday, September 09, 2001 10:29 PM Subject: Re: [PHP-CVS] cvs: php4 /ext/standard php_string.h string.c > hi, > > IMHO this is incorrect again :)) > > you should not return when there are some translations, because it is a > common practice to have code with mixed line endings [most commonly > win/unix]. > > the perfect solution [only like algorithm] is: > ereg_replace('\n\r?|\r','<br //>') > > talking for speed - as far as i know boyer-moore algorithm is not good with > short strings :)) so instead of three times calling boyer_str_to_str, it > will be better to scan the string once and code the above regexp in two ifs > ;) > > anyway not be only speaking, if it will be helpful, i can send a patch on > this... > > b. > > ----- Original Message ----- > From: "Derick Rethans" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Sunday, September 09, 2001 3:55 PM > Subject: [PHP-CVS] cvs: php4 /ext/standard php_string.h string.c > > > > derick Sun Sep 9 08:55:48 2001 EDT > > > > Modified files: > > /php4/ext/standard php_string.h string.c > > Log: > > - Really fix nl2br now... it's actaulyl faster now > > > > > > Index: php4/ext/standard/php_string.h > > diff -u php4/ext/standard/php_string.h:1.51 > php4/ext/standard/php_string.h:1.52 > > --- php4/ext/standard/php_string.h:1.51 Tue Sep 4 05:35:53 2001 > > +++ php4/ext/standard/php_string.h Sun Sep 9 08:55:48 2001 > > @@ -17,7 +17,7 @@ > > > +----------------------------------------------------------------------+ > > */ > > > > -/* $Id: php_string.h,v 1.51 2001/09/04 09:35:53 sterling Exp $ */ > > +/* $Id: php_string.h,v 1.52 2001/09/09 12:55:48 derick Exp $ */ > > > > /* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */ > > > > @@ -117,7 +117,7 @@ > > 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); > > Index: php4/ext/standard/string.c > > diff -u php4/ext/standard/string.c:1.238 php4/ext/standard/string.c:1.239 > > --- php4/ext/standard/string.c:1.238 Sun Sep 9 07:42:36 2001 > > +++ php4/ext/standard/string.c Sun Sep 9 08:55:48 2001 > > @@ -18,7 +18,7 @@ > > > +----------------------------------------------------------------------+ > > */ > > > > -/* $Id: string.c,v 1.238 2001/09/09 11:42:36 derick Exp $ */ > > +/* $Id: string.c,v 1.239 2001/09/09 12:55:48 derick Exp $ */ > > > > /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ > > > > @@ -2473,10 +2473,11 @@ > > > > /* {{{ 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) { > > @@ -2486,7 +2487,7 @@ > > > > if (char_count==0) { > > ZVAL_STRINGL(result, str, len, 1); > > - return; > > + return 0; > > } > > > > Z_STRLEN_P(result) = len + (char_count * (to_len - 1)); > > @@ -2495,6 +2496,7 @@ > > > > 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++; > > @@ -2505,6 +2507,7 @@ > > } > > } > > *target = 0; > > + return replaced; > > } > > /* }}} */ > > > > @@ -2992,13 +2995,12 @@ > > 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); > > } > > /* }}} */ > > > > @@ -3786,6 +3788,6 @@ > > * 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 > > */ > > > > > > > > -- > > PHP CVS Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > > > > > > -- > PHP CVS Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]