|
9 | 9 | # width ::= <integer> |
10 | 10 | # prec ::= <integer> |
11 | 11 | # type ::= 'b' | 'c' | 'd' | 'e' | 'E' | 'f' | 'F' | 'g' | 'G' | |
12 | | -# 'n' | 'o' | 'x' | 'X' | 's' |
| 12 | +# 'n' | 'o' | 'x' | 'X' | 's' | '%' |
13 | 13 | # |
14 | 14 | # Please refer to http://docs.python.org/2/library/string.html#formatspec |
15 | 15 | # for more details |
16 | 16 | # |
17 | 17 |
|
18 | 18 | ## FormatSpec type |
19 | 19 |
|
20 | | -const _numtypchars = Set(['b', 'd', 'e', 'E', 'f', 'F', 'g', 'G', 'n', 'o', 'x', 'X']) |
| 20 | +const _numtypchars = Set(['b', 'd', 'e', 'E', 'f', 'F', 'g', 'G', 'n', 'o', 'x', 'X', '%']) |
21 | 21 |
|
22 | 22 | _tycls(c::AbstractChar) = |
23 | 23 | (c == 'd' || c == 'n' || c == 'b' || c == 'o' || c == 'x') ? 'i' : |
24 | | - (c == 'e' || c == 'f' || c == 'g') ? 'f' : |
| 24 | + (c == 'e' || c == 'f' || c == 'g' || c == '%') ? 'f' : |
25 | 25 | (c == 'c') ? 'c' : |
26 | 26 | (c == 's') ? 's' : |
27 | 27 | error("Invalid type char $(c)") |
|
108 | 108 |
|
109 | 109 | ## parse FormatSpec from a string |
110 | 110 |
|
111 | | -const _spec_regex = r"^(.?[<^>])?([ +-])?(#)?(\d+)?([,_])?(.\d+)?([bcdeEfFgGnosxX])?$" |
| 111 | +const _spec_regex = r"^(.?[<^>])?([ +-])?(#)?(\d+)?([,_])?(.\d+)?([bcdeEfFgGnosxX%])?$" |
112 | 112 |
|
113 | 113 | function FormatSpec(s::AbstractString) |
114 | 114 | # default spec |
@@ -204,7 +204,7 @@ function printfmt(io::IO, fs::FormatSpec, x) |
204 | 204 | elseif cls == 'f' |
205 | 205 | fx = float(x) |
206 | 206 | if isfinite(fx) |
207 | | - ty == 'f' || ty == 'F' ? _pfmt_f(io, fs, fx) : |
| 207 | + ty == 'f' || ty == 'F' || ty == '%' ? _pfmt_f(io, fs, fx) : |
208 | 208 | ty == 'e' || ty == 'E' ? _pfmt_e(io, fs, fx) : _pfmt_g(io, fs, fx) |
209 | 209 | else |
210 | 210 | _pfmt_specialf(io, fs, fx) |
|
0 commit comments