[MacRuby-devel] [MacRuby] #608: rb_str_format() does not handle the "field width" flag for strings

MacRuby ruby-noreply at macosforge.org
Tue Feb 9 17:36:35 PST 2010


#608: rb_str_format() does not handle the "field width" flag for strings
----------------------------------------+-----------------------------------
 Reporter:  martinlagardette@…          |       Owner:  lsansonetti@…        
     Type:  defect                      |      Status:  new                  
 Priority:  minor                       |   Milestone:                       
Component:  MacRuby                     |    Keywords:                       
----------------------------------------+-----------------------------------

Comment(by danielcavanagh@…):

 ok, i've finished and the diff above has been updated. as i explained
 before, to support %b we have to unfortunately fully reimplement sprintf.
 with this diff, sprintf now matches ruby 1.9's, except for these
 differences:

 - this implementation fully supports named (eg. "%<key>d") arguments. ruby
 1.9 only supports them for the type itself, not for the width and
 precision

 - this implementation is more permissive of the structure of the format
 string. for instance, ruby 1.9 will raise if there are multiple widths or
 precisions, etc., or if they aren't in their 'proper' positions. there's
 no technical reason for this, it's just a relic of the past, so i've
 allowed everything to be specified anywhere and multiple times (except for
 the type itself, of course) and the last one wins. for instance,
 "%.8#+.6d" would raise an arg error in ruby 1.9, but this sprintf would
 pass them and the precision would be set to 6

 - the char type "%c" allows a multi-char string as an argument and simply
 chops off the end. ruby 1.9 raises on multi-char strings. i'm wary of this
 difference. any thoughts?

 it passes the ruby 1.9 sprintf tests except for the above-mentioned lack
 of raising, and what appears to be a float rounding difference. i believe
 this to be a platform difference (as this impl. simply reuses c's sprintf,
 the same as ruby 1.9), so i've ignored that one. still to be implemented
 is proper ruby 1.9 encoding support, but that can wait til macruby in
 general supports it

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/608#comment:2>
MacRuby <http://macruby.org/>



More information about the MacRuby-devel mailing list