[macruby-changes] [4338] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jul 8 18:37:59 PDT 2010
Revision: 4338
http://trac.macosforge.org/projects/ruby/changeset/4338
Author: martinlagardette at apple.com
Date: 2010-07-08 18:37:55 -0700 (Thu, 08 Jul 2010)
Log Message:
-----------
Fix `IO#gets` (and #770)
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-07-09 00:03:00 UTC (rev 4337)
+++ MacRuby/trunk/io.c 2010-07-09 01:37:55 UTC (rev 4338)
@@ -1362,13 +1362,17 @@
if (line_limit != -1) {
rb_bstr_resize(bstr, line_limit);
uint8_t *bytes = rb_bstr_bytes(bstr);
- rb_io_read_internal(io_struct, bytes, line_limit);
-#if 0 // TODO
- CFRange r = CFStringFind((CFStringRef)bstr, (CFStringRef)sep, 0);
- if (r.location != kCFNotFound) {
- CFDataSetLength(data, r.location);
+ long r = rb_io_read_internal(io_struct, bytes, line_limit);
+
+ CFRange range = CFStringFind((CFStringRef)bstr, (CFStringRef)sep, 0);
+ if (range.location != kCFNotFound) {
+ rb_io_create_buf(io_struct);
+ long rest_size = r - (range.location + 1);
+ CFDataAppendBytes(io_struct->buf, bytes + range.location + 1, rest_size);
+ r = range.location + 1;
}
-#endif
+ // Resize the buffer to whatever was actually read (can be different from asked size)
+ rb_bstr_resize(bstr, r);
}
else {
const char *sepstr = RSTRING_PTR(sep);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100708/471c9ec7/attachment.html>
More information about the macruby-changes
mailing list