Revision
148
Author
lsansonetti@apple.com
Date
2008-04-17 18:03:34 -0700 (Thu, 17 Apr 2008)

Log Message

fixing #chop, #chomp

Modified Paths

Diff

Modified: MacRuby/trunk/string.c (147 => 148)


--- MacRuby/trunk/string.c	2008-04-18 00:46:06 UTC (rev 147)
+++ MacRuby/trunk/string.c	2008-04-18 01:03:34 UTC (rev 148)
@@ -6069,12 +6069,23 @@
 {
 #if WITH_OBJC
     long n;
+    const char *p;
+    CFRange r;
 
     n = CFStringGetLength((CFStringRef)str);
     if (n == 0)
 	return Qnil;
     rb_str_modify(str);
-    CFStringDelete((CFMutableStringRef)str, CFRangeMake(n - 1, 1));
+    p = RSTRING_CPTR(str);
+    r = CFRangeMake(n - 1, 1);
+    if (n >= 2 && p[n - 1] == '\n' && p[n - 2] == '\r') {
+	/* We need this to pass the tests, but this is most probably 
+	 * unnecessary.
+	 */
+	r.location--;
+	r.length++;
+    }
+    CFStringDelete((CFMutableStringRef)str, r);
     return str;
 #else
     if (RSTRING_LEN(str) > 0) {
@@ -6139,7 +6150,8 @@
     long n;
     CFRange range_result;
 
-    rb_scan_args(argc, argv, "01", &rs);
+    if (rb_scan_args(argc, argv, "01", &rs) == 0)
+	rs = rb_rs;
     rb_str_modify(str);
     n = CFStringGetLength((CFStringRef)str);
     if (NIL_P(rs)) {