[PHP-DEV] CVS update: php31/ext/standard From: rasmus (php-dev <email protected>)
Date: 05/31/98

Date: Sunday May 31, 1998 @ 17:21
Author: rasmus

Update of /repository/php31/ext/standard
In directory asf:/tmp/cvs-serv29642/ext/standard

Modified Files:
        basic_functions.c php3_string.h string.c
Log Message:
trim/ltrim/rtrim patch for 3.1 tree

Index: php31/ext/standard/basic_functions.c
diff -c php31/ext/standard/basic_functions.c:1.9 php31/ext/standard/basic_functions.c:1.10
*** php31/ext/standard/basic_functions.c:1.9 Sun May 31 16:45:08 1998
--- php31/ext/standard/basic_functions.c Sun May 31 17:21:49 1998
***************
*** 127,132 ****
--- 127,134 ----
          {"addslashes", php3_addslashes, NULL},
          {"chop", php3_chop, NULL},
          {"trim", php3_trim, NULL},
+ {"ltrim", php3_ltrim, NULL},
+ {"rtrim", php3_chop, NULL},
          {"pos", array_current, first_arg_force_ref},
  
          {"fsockopen", php3_fsockopen, NULL},
Index: php31/ext/standard/php3_string.h
diff -c php31/ext/standard/php3_string.h:1.3 php31/ext/standard/php3_string.h:1.4
*** php31/ext/standard/php3_string.h:1.3 Sun May 31 17:03:21 1998
--- php31/ext/standard/php3_string.h Sun May 31 17:21:50 1998
***************
*** 29,35 ****
   */
  
  
! /* $Id: php3_string.h,v 1.3 1998/05/31 21:03:21 rasmus Exp $ */
  
  #ifndef _PHPSTRING_H
  #define _PHPSTRING_H
--- 29,35 ----
   */
  
  
! /* $Id: php3_string.h,v 1.4 1998/05/31 21:21:50 rasmus Exp $ */
  
  #ifndef _PHPSTRING_H
  #define _PHPSTRING_H
***************
*** 42,47 ****
--- 42,48 ----
  extern void php3_strcmp(INTERNAL_FUNCTION_PARAMETERS);
  extern void php3_chop(INTERNAL_FUNCTION_PARAMETERS);
  extern void php3_trim(INTERNAL_FUNCTION_PARAMETERS);
+ extern void php3_ltrim(INTERNAL_FUNCTION_PARAMETERS);
  extern void soundex(INTERNAL_FUNCTION_PARAMETERS);
  
  extern void php3_explode(INTERNAL_FUNCTION_PARAMETERS);
Index: php31/ext/standard/string.c
diff -c php31/ext/standard/string.c:1.5 php31/ext/standard/string.c:1.6
*** php31/ext/standard/string.c:1.5 Sun May 31 17:03:21 1998
--- php31/ext/standard/string.c Sun May 31 17:21:50 1998
***************
*** 30,36 ****
   */
  
  
! /* $Id: string.c,v 1.5 1998/05/31 21:03:21 rasmus Exp $ */
  #ifdef THREAD_SAFE
  #include "tls.h"
  #endif
--- 30,36 ----
   */
  
  
! /* $Id: string.c,v 1.6 1998/05/31 21:21:50 rasmus Exp $ */
  #ifdef THREAD_SAFE
  #include "tls.h"
  #endif
***************
*** 69,75 ****
          RETURN_LONG(php3_binary_strcmp(s1,s2));
  }
  
-
  void php3_chop(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *str;
--- 69,74 ----
***************
*** 99,104 ****
--- 98,142 ----
  }
  
  void php3_trim(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *str;
+ register int i;
+ TLS_VARS;
+
+ if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &str) == FAILURE) {
+ 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;
+ }
+ }
+ 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;
+ }
+ RETURN_FALSE;
+ }
+
+ void php3_ltrim(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *str;
          register int i;