Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed a few bugs in #sprintf

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@3819 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
commit a539763dfe79a0a84b98c401a76e664956fb9de1 1 parent 8b811c2
Laurent Sansonetti authored
Showing with 15 additions and 12 deletions.
  1. +15 −12 sprintf.c
View
27 sprintf.c
@@ -435,7 +435,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
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 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
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)

0 comments on commit a539763

Please sign in to comment.
Something went wrong with that request. Please try again.