[macruby-changes] [3819] MacRuby/trunk/sprintf.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Mar 18 20:09:55 PDT 2010
Revision: 3819
http://trac.macosforge.org/projects/ruby/changeset/3819
Author: lsansonetti at apple.com
Date: 2010-03-18 20:09:53 -0700 (Thu, 18 Mar 2010)
Log Message:
-----------
fixed a few bugs in #sprintf
Modified Paths:
--------------
MacRuby/trunk/sprintf.c
Modified: MacRuby/trunk/sprintf.c
===================================================================
--- MacRuby/trunk/sprintf.c 2010-03-19 02:10:49 UTC (rev 3818)
+++ MacRuby/trunk/sprintf.c 2010-03-19 03:09:53 UTC (rev 3819)
@@ -435,7 +435,8 @@
continue;
}
if (format_str[i + 1] == '%') {
- cstr_update(&format_str, &format_str_capa, i, 1, 0);
+ num = cstr_update(&format_str, &format_str_capa, i, 1, 0);
+ format_len += num;
continue;
}
@@ -747,23 +748,25 @@
arg = rb_big2str(num, base);
if (!sign_pad && IS_NEG(num) && negative_pad != 0) {
- break; // TODO
-#if 0
- UChar neg = CFStringGetCharacterAtIndex(negative_pad, 0);
- char *str_ptr = (char *)RSTRING_PTR(arg) + 1;
+ UChar neg = rb_str_get_uchar(negative_pad, 0);
if (base == 8) {
- *str_ptr |= ((~0 << 3) >> ((3 * strlen(str_ptr)) %
- (sizeof(BDIGIT) * 8))) & ~(~0 << 3);
+ UChar c = rb_str_get_uchar(arg, 1);
+ const long len = rb_str_chars_len(arg) - 1;
+ c |= ((~0 << 3) >> ((3 * len)
+ % (sizeof(BDIGIT) * 8))) & ~(~0 << 3);
+ rb_str_update(arg, 1, 1, rb_unicode_str_new(&c, 1));
}
- while (*str_ptr++ == neg) {
+ for (int i = 1, count = rb_str_chars_len(arg); i < count;
+ i++) {
+ if (rb_str_get_uchar(arg, i) != neg) {
+ break;
+ }
num_index++;
}
- rb_str_update(arg, 0, num_index, (VALUE)negative_pad);
- rb_str_update(arg, 0, 0, (VALUE)CFSTR(".."));
+ rb_str_update(arg, 0, num_index, negative_pad);
+ rb_str_update(arg, 0, 0, rb_str_new2(".."));
num_index = 2;
-#endif
}
-
if (precision_flag) {
pad_format_value(arg, num_index,
precision + (IS_NEG(num)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100318/c7c6260c/attachment.html>
More information about the macruby-changes
mailing list