CVS update: php3/functions

From: Date: Fri, 02 Jul 1999 17:37:33 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-7998@lists.php.net to get a copy of this message
Date: Friday July 2, 1999 @ 13:37 Author: sas Update of /repository/php3/functions In directory php:/tmp/cvs-serv2364 Modified Files: string.c Log Message: fix ltrim behaviour Index: php3/functions/string.c diff -u php3/functions/string.c:1.193 php3/functions/string.c:1.194 --- php3/functions/string.c:1.193 Wed Jun 16 07:34:22 1999 +++ php3/functions/string.c Fri Jul 2 13:37:33 1999 @@ -30,7 +30,7 @@ */ -/* $Id: string.c,v 1.193 1999/06/16 11:34:22 ssb Exp $ */ +/* $Id: string.c,v 1.194 1999/07/02 17:37:33 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif @@ -228,6 +228,26 @@ RETVAL_STRINGL(c, len, 1); } +PHPAPI void _php3_ltrim(pval *str, pval * return_value) +{ + register int i; + + int len = str->value.str.len; + int trimmed = 0; + char *c = str->value.str.val; + for (i = 0; i < len; i++) { + if (c[i] == ' ' || c[i] == '\n' || c[i] == '\r' || + c[i] == '\t' || c[i] == '\v') { + trimmed++; + } else { + break; + } + } + len-=trimmed; + c+=trimmed; + RETVAL_STRINGL(c, len, 1); +} + /* {{{ proto string trim(string str) Strip whitespace from the beginning and end of a string */ void php3_trim(INTERNAL_FUNCTION_PARAMETERS) @@ -242,31 +262,10 @@ convert_to_string(str); if (str->type == IS_STRING) { - int len = str->value.str.len; - int trimmed = 0; - char *c = str->value.str.val; - for (i = 0; i < len; i++) { - if (c[i] == ' ' || c[i] == '\n' || c[i] == '\r' || - c[i] == '\t' || c[i] == '\v') { - trimmed++; - } else { - break; - } - } - len-=trimmed; - c+=trimmed; - for (i = len - 1; i >= 0; i--) { - if (c[i] == ' ' || c[i] == '\n' || c[i] == '\r' || - c[i] == '\t' || c[i] == '\v') { - len--; - } else { - break; - } - } - RETVAL_STRINGL(c, len, 1); - return; + _php3_trim(str, return_value); + } else { + RETVAL_FALSE; } - RETURN_FALSE; } /* }}} */ @@ -282,7 +281,7 @@ } convert_to_string(str); if (str->type == IS_STRING) { - _php3_trim(str, return_value); + _php3_ltrim(str, return_value); return; } RETURN_FALSE;

« previous php.dev (#7998) next »