Add std.fmt.parseIntSizeSuffix and use for --maxrss#14976
Conversation
| } | ||
| if (without_i.len == 0) return error.InvalidCharacter; | ||
| const orders_of_magnitude: usize = switch (without_i[without_i.len - 1]) { | ||
| 'k', 'K' => 1, |
There was a problem hiding this comment.
Multiple ways of doing this doesn't feel necessary, but not sure if hackability is more important in this case.
There was a problem hiding this comment.
You mean the k/K? I did that because the SI and IEC use different capitalizations for the K, which I learned from reading the fmtIntSize docstrings.
lib/std/fmt.zig
Outdated
| if (mem.endsWith(u8, buf, "B")) without_b.len -= 1; | ||
| var without_i = without_b; | ||
| var base: usize = 1000; | ||
| if (mem.endsWith(u8, without_b, "i")) { |
There was a problem hiding this comment.
sno/if (mem.endsWith(u8, without_b, "i")) {/if (mem.endsWith(u8, without_i, "i")) {
There was a problem hiding this comment.
Wouldn't that be inconsistent with the first case? On line 1921, it checks the slice defined before without_b, so I figured that this line should check the slice defined before without_i.
lib/std/fmt.zig
Outdated
| var without_suffix = without_i; | ||
| if (orders_of_magnitude > 0) { | ||
| without_suffix.len -= 1; | ||
| } else if (without_i.len != without_b.len) { |
There was a problem hiding this comment.
If there's an i but no magnitude prefix (see the "2iB" test case)
Fixes #14955