[macruby-changes] [148] MacRuby/trunk/string.c

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 17 18:03:34 PDT 2008


Revision: 148
          http://trac.macosforge.org/projects/ruby/changeset/148
Author:   lsansonetti at apple.com
Date:     2008-04-17 18:03:34 -0700 (Thu, 17 Apr 2008)

Log Message:
-----------
fixing #chop, #chomp

Modified Paths:
--------------
    MacRuby/trunk/string.c

Modified: MacRuby/trunk/string.c
===================================================================
--- 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)) {

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macruby-changes/attachments/20080417/6f9e8abc/attachment.html


More information about the macruby-changes mailing list