diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | sprintf.c | 18 |
2 files changed, 23 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Mon Jun 12 22:25:09 2006 Yukihiro Matsumoto <matz@ruby-lang.org> + + * sprintf.c (rb_f_sprintf): adjust precision length to prevent + splitting multi-byte characters. [ruby-list:42389] + Sun Jun 11 23:20:07 2006 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/optparse.rb (OptionParser::Arguable#getopts): pass self to the @@ -13,6 +13,7 @@ **********************************************************************/ #include "ruby.h" +#include "re.h" #include <ctype.h> #include <math.h> @@ -413,6 +414,23 @@ rb_f_sprintf(argc, argv) len = prec; } } + { + char *s, *send; + long l; + + s = RSTRING(str)->ptr; + send = s + RSTRING(str)->len; + l = 0; + while (s < send) { + long n = mbclen(*s); + if (l + n > len) { + len = l; + break; + } + l += n; + s += n; + } + } if (flags&FWIDTH) { if (width > len) { CHECK(width); |