[macruby-changes] [3605] MacRuby/branches/icu/string.c

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 24 14:18:37 PST 2010


Revision: 3605
          http://trac.macosforge.org/projects/ruby/changeset/3605
Author:   lsansonetti at apple.com
Date:     2010-02-24 14:18:36 -0800 (Wed, 24 Feb 2010)
Log Message:
-----------
fixed splicing before or after the string

Modified Paths:
--------------
    MacRuby/branches/icu/string.c

Modified: MacRuby/branches/icu/string.c
===================================================================
--- MacRuby/branches/icu/string.c	2010-02-24 22:14:38 UTC (rev 3604)
+++ MacRuby/branches/icu/string.c	2010-02-24 22:18:36 UTC (rev 3605)
@@ -706,20 +706,35 @@
     // self[pos..pos+len] = str
     assert(pos >= 0 && len >= 0);
 
-    character_boundaries_t beg
-	= str_get_character_boundaries(self, pos, ucs2_mode);
+    character_boundaries_t beg, end;
 
-    // TODO: probably call str_cannot_cut_surrogate()
-    assert(beg.start_offset_in_bytes != -1);
-    assert(beg.end_offset_in_bytes != -1);
+    if (pos + len == 0) {
+	// Positioning before the string.
+	const long offset = 0;
+	beg.start_offset_in_bytes = beg.end_offset_in_bytes = offset;
+	end.start_offset_in_bytes = end.end_offset_in_bytes = offset;
+    }
+    else if (len == 0 && str_length(self, ucs2_mode) == pos) {
+	// Positioning after the string.
+	const long offset = self->length_in_bytes;
+	beg.start_offset_in_bytes = beg.end_offset_in_bytes = offset;
+	end.start_offset_in_bytes = end.end_offset_in_bytes = offset;
+    }
+    else {
+	// Positioning in the string.
+	beg = str_get_character_boundaries(self, pos, ucs2_mode);
 
-    character_boundaries_t end
-	= str_get_character_boundaries(self, pos + len - 1, ucs2_mode);
+	// TODO: probably call str_cannot_cut_surrogate()
+	assert(beg.start_offset_in_bytes != -1);
+	assert(beg.end_offset_in_bytes != -1);
 
-    // TODO: probably call str_cannot_cut_surrogate()
-    assert(end.start_offset_in_bytes != -1);
-    assert(end.end_offset_in_bytes != -1);
+	end = str_get_character_boundaries(self, pos + len - 1, ucs2_mode);
 
+	// TODO: probably call str_cannot_cut_surrogate()
+	assert(end.start_offset_in_bytes != -1);
+	assert(end.end_offset_in_bytes != -1);
+    }
+
     const long bytes_to_splice = end.end_offset_in_bytes
 	- beg.start_offset_in_bytes;
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100224/977bde44/attachment-0001.html>


More information about the macruby-changes mailing list