Skip to content

Commit

Permalink
* lib/scanf.rb: fix max width modifier for %f.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Mar 28, 2010
1 parent 1392791 commit 1720e7e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Sun Mar 28 10:03:51 2010 NARUSE, Yui <[email protected]>

* lib/scanf.rb: fix max width modifier for %f.

Sun Mar 28 10:35:45 2010 Ryan Davis <[email protected]>

* lib/minitest/*.rb: Imported minitest 1.6.0 r5717.
Expand Down
5 changes: 3 additions & 2 deletions lib/scanf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,12 @@ def initialize(str)

# %f
when /%\*?[efgEFG]/
[ '([-+]?((\d+(?>(?=[^\d.]|$)))|(\d*(\.(\d*([eE][-+]?\d+)?)))))', :extract_float ]
[ '([-+]?(?:\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))', :extract_float ]

# %5f
when /%\*?(\d+)[efgEFG]/
[ "(\\S{1,#{$1}})", :extract_float ]
[ '(?=[-+]?(?:\d+(?![\d.])|\d*\.\d*(?:[eE][-+]?\d+)?))' +
"(\\S{1,#{$1}})", :extract_float ]

# %5s
when /%\*?(\d+)s/
Expand Down
2 changes: 1 addition & 1 deletion test/scanf/test_scanf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def tests
[ "%[[:upper:]]", "ABCdefGHI", [ "ABC" ] ],

# Testing 'f'
[ "%2f", "x", [0.0] ], # width-floats match anything (by design)
[ "%2f", "x", [] ],
[ "%F", "1.23e45", [1.23e+45] ],
[ "%e", "3.25ee", [3.25] ],
[ "%E", "3..25", [3.0] ],
Expand Down

0 comments on commit 1720e7e

Please sign in to comment.