CVS update: php3/functions
| From: | fmk | Date: | Tue, 13 Apr 1999 14:28:47 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-5029@lists.php.net to get a copy of this message | ||
Date: Tuesday April 13, 1999 @ 10:28
Author: fmk
Update of /repository/php3/functions
In directory asf:/u/temp/cvs-serv5982
Modified Files:
string.c php3_string.h
Log Message:
Making trim() callable from other modules
Index: php3/functions/string.c
diff -c php3/functions/string.c:1.182 php3/functions/string.c:1.183
*** php3/functions/string.c:1.182 Tue Mar 30 07:43:30 1999
--- php3/functions/string.c Tue Apr 13 10:28:46 1999
***************
*** 30,36 ****
*/
! /* $Id: string.c,v 1.182 1999/03/30 12:43:30 rasmus Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
--- 30,36 ----
*/
! /* $Id: string.c,v 1.183 1999/04/13 14:28:46 fmk Exp $ */
#ifdef THREAD_SAFE
#include "tls.h"
#endif
***************
*** 154,159 ****
--- 154,187 ----
}
/* }}} */
+ PHPAPI void _php3_trim(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;
+ 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);
+ }
+
/* {{{ proto string trim(string str)
Strip whitespace from the beginning and end of a string */
void php3_trim(INTERNAL_FUNCTION_PARAMETERS)
***************
*** 208,227 ****
WRONG_PARAM_COUNT;
}
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;
! }
! }
! RETVAL_STRINGL(c+trimmed, len-trimmed, 1);
return;
}
RETURN_FALSE;
--- 236,243 ----
WRONG_PARAM_COUNT;
}
convert_to_string(str);
if (str->type == IS_STRING) {
! _php3_trim(str, return_value);
return;
}
RETURN_FALSE;
Index: php3/functions/php3_string.h
diff -c php3/functions/php3_string.h:1.39 php3/functions/php3_string.h:1.40
*** php3/functions/php3_string.h:1.39 Tue Mar 30 07:55:13 1999
--- php3/functions/php3_string.h Tue Apr 13 10:28:46 1999
***************
*** 29,35 ****
*/
! /* $Id: php3_string.h,v 1.39 1999/03/30 12:55:13 rasmus Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
--- 29,35 ----
*/
! /* $Id: php3_string.h,v 1.40 1999/04/13 14:28:46 fmk Exp $ */
#ifndef _PHPSTRING_H
#define _PHPSTRING_H
***************
*** 100,105 ****
--- 100,106 ----
extern PHPAPI void _php3_stripslashes(char *string, int *len);
extern PHPAPI void _php3_dirname(char *str, int len);
extern PHPAPI char *php3i_stristr(unsigned char *s, unsigned char *t);
+ extern PHPAPI void _php3_trim(pval *str, pval * return_value);
extern PHPAPI void _php3_strip_tags(char *rbuf, int state);
#if 0
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net