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

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

Update of /repository/php3/functions
In directory asf:/tmp/cvs-serv29521/functions

Modified Files:
        basic_functions.c php3_string.h string.c
Log Message:
Take Jim's advice and make trim() strip whitespace from both ends and
create an ltrim() function that just strips at the start of the string.
Also add rtrim() alias to chop() for completeness sake.

Index: php3/functions/basic_functions.c
diff -c php3/functions/basic_functions.c:1.179 php3/functions/basic_functions.c:1.180
*** php3/functions/basic_functions.c:1.179 Sun May 31 12:42:54 1998
--- php3/functions/basic_functions.c Sun May 31 17:16:58 1998
***************
*** 128,133 ****
--- 128,135 ----
          {"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: php3/functions/php3_string.h
diff -c php3/functions/php3_string.h:1.17 php3/functions/php3_string.h:1.18
*** php3/functions/php3_string.h:1.17 Sun May 31 16:59:49 1998
--- php3/functions/php3_string.h Sun May 31 17:16:59 1998
***************
*** 29,35 ****
   */
  
  
! /* $Id: php3_string.h,v 1.17 1998/05/31 20:59:49 rasmus Exp $ */
  
  #ifndef _PHPSTRING_H
  #define _PHPSTRING_H
--- 29,35 ----
   */
  
  
! /* $Id: php3_string.h,v 1.18 1998/05/31 21:16:59 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: php3/functions/string.c
diff -c php3/functions/string.c:1.122 php3/functions/string.c:1.123
*** php3/functions/string.c:1.122 Sun May 31 16:59:50 1998
--- php3/functions/string.c Sun May 31 17:16:59 1998
***************
*** 30,36 ****
   */
  
  
! /* $Id: string.c,v 1.122 1998/05/31 20:59:50 rasmus Exp $ */
  #ifdef THREAD_SAFE
  #include "tls.h"
  #endif
--- 30,36 ----
   */
  
  
! /* $Id: string.c,v 1.123 1998/05/31 21:16:59 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;