I am writing an emulator for a machine with the printf opcode, and although I know the Formatter class, which is probably good enough for the actual formatting of strings, I need a way to count the number of arguments that are consumed by printf.
At the top of my head, I could do something with a regex to count the number of “%”, but I'm not too familiar with format strings, so I could not count correctly ... (excluding escaped, etc. )
edit: I really need the number of parameters, as well as matching the parameter # with the type of the parameter, so for example, "hello% s% +. 3i" will give {0 → String, 1 → Integer}
Bwmat source share