rev 592 - in trunk: pr/test src

SVN User <[email protected]> Thu, 10 Jun 2004 01:20:21 -0400
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-06-10 01:20:18 -0400 (Thu, 10 Jun 2004)
New Revision: 592

Modified:
   trunk/pr/test/test.pr
   trunk/src/builtins-string.c
Log:
fixed string.rstrip and string.strip

Modified: trunk/pr/test/test.pr
===================================================================
--- trunk/pr/test/test.pr	2004-06-10 05:03:03 UTC (rev 591)
+++ trunk/pr/test/test.pr	2004-06-10 05:20:18 UTC (rev 592)
@@ -1,43 +1,36 @@
 #!/usr/bin/env prothon
 
 def err(n):
-	print 'error', n
+	print 'test',n,'failed'
 	Sys.exit(1)
 
-x = 1
-if x != 1: err(0)
-	
-for i in 200:
-	x *= 2
+x = "abcdefghijklm"
 
-y = 2**200
-
-if x != y: 
-	print 'x:',x
-	print 'y:',y
+if "c:bc:acegi:mlkjih" !=  x[2]+':'+x[1:3]+':'+x[0:10:2]+':'+x[12:6:-1]:
 	err(1)
-if x != 1606938044258990275541962092341162602522202993782792835301376:
+
+x = "abcdef"
+
+if "e:de:def:ab:fed:fedcba:abcdef" !=  x[-2]+':'+x[-3:-1]+':'+x[3:]+':'+x[:2]+':'+x[:2:-1]+':'+x[::-1]+':'+x[:]:
 	err(2)
 
-for i in 200:
-	x //=2
+if 3 !=  Len("abc"):  err(3)
 
-if x != 1: err(3)
+if "ABC" !=  "abc".upper(): err(4)
 
-x = 254373265453637
-if -(823 * 2134 + 3184536 - 42312 % 311) | 19234567 & 149578376456 != -4915202:
-	err(4)
+if "abc" !=  "ABC".lower(): err(5)
 
-if -(8211442569234385238487474353 * 212847346352034947352764 + 31842289378376456945234123236
-        - 44872283873746635434256223262312 % 3387611
-        ) | 192328437462345263464564567 & 1495728438374645645346368376456 != 
-				-1747783760583674902504339775785929746473575241492788:
-	err(5)
+if "Abc def" !=  "abc def".capitalize(): err(6)
 
-y = 1002003004005006007008009000100200300400500600700800900
-print """
---- All tests passed ---
+if "Abc Def" !=  "abc def".capWords(): err(7)
 
-The following should match:
-1002003004005006007008009000100200300400500600700800900"""
-print y
\ No newline at end of file
+if "<x >" != '<'+" x ".lStrip()+'>': err(8)
+
+if "< x>" !=  '<'+" x ".rStrip()+'>': err(9)
+
+if "<x>" !=  '<'+" x ".strip()+'>': err(10)
+
+print '\nall tests passed\n'
+
+
+

Modified: trunk/src/builtins-string.c
===================================================================
--- trunk/src/builtins-string.c	2004-06-10 05:03:03 UTC (rev 591)
+++ trunk/src/builtins-string.c	2004-06-10 05:20:18 UTC (rev 592)
@@ -659,34 +659,35 @@
 
 DEF(String, rStrip, NULL) {
 	// Count whitespace at the end.
-	char* cstr = pr2c_strptr(ist, self)+pr_strlen(self)-1;
+	char *self_str, *cstr;
 	size_t result_len = 0;
 
 	BIN_CONTENT_CHK(String);
 
-	while (isspace(*cstr)) {
+	self_str = pr2c_strptr(ist, self);
+	cstr = self_str + strlen(self_str) - 1;
+	while (cstr >= self_str && isspace(*cstr)) {
 		--cstr;
 	}
-	result_len = cstr-pr2c_strptr(ist, self)+1;
+	result_len = cstr - self_str + 1;
 	
 	// Create the copy.
-	return new_string_n_obj(ist,pr2c_strptr(ist, self),result_len);
+	return new_string_n_obj(ist, self_str, result_len);
 }
 
 DEF(String, strip, NULL) {
-	char *cstr2, *cstr = pr2c_strptr(ist, self);
+	char *cstr2, *cstr;
 	size_t result_len;
 
 	BIN_CONTENT_CHK(String);
-
+	cstr = pr2c_strptr(ist, self);
 	while (isspace(*cstr)) {
 		++cstr;
 	}
-	
 	// Count whitespace at the end.
-	cstr2 = pr2c_strptr(ist, self)+pr_strlen(self)-1;
+	cstr2 = cstr+strlen(cstr)-1;
 	result_len = 0;
-	while (isspace(*cstr2)) {
+	while (cstr2 >= cstr && isspace(*cstr2)) {
 		--cstr2;
 	}
 	result_len = cstr2-cstr+1;