- unify way of commenting funcs. in header, or in source file?
- minus
- plus
- zero
- space
- dot
- minus
- plus
- zero
- space
- dot
- any '-' invalidates any '0' and any ' '
- you can wildly mix -, + and 0's. but, rule No.1, 0's will be ignored alongside -'s. still - and + will count!
- after any (positive) number there can only be a single '.' and eventually another number but nothing else (except the conversion char)!
- also the mighty '#' + conv_char cannot be after the
- so it seems, there can be any wild mix of the flags '+', '-', ' ', '#' and '0' ('+' and '#x' is a bit special..) followed by a number a dot and a number. that's it. so for example: "%+-- 0#0 + -x" is perfectly valid this means: we can simply test valid compl_convs based on this ruleset!
- the '#' rules:
- only is supposed to work with 'x', 'X'
- '-' present => ignore '0'
- ' ' and '0' shall work together
- '+' and '0' shall work together, but '+' overrides space anyway
- '.' superceedes '0'
- '-' is ignored
- ' ' and '+' are respected
- if width <= prec number is zero padded. if width > prec number including sign is ' ' padded until prec or sign
- if '-' is given the width-padding happens to the right of the number
-
conversions: • %c Prints a single character. • %s Prints a string (as defined by the common C convention). • %p The void * pointer argument has to be printed in hexadecimal format. • %d Prints a decimal (base 10) number. • %i Prints an integer in base 10. • %u Prints an unsigned decimal (base 10) number. • %x Prints a number in hexadecimal (base 16) lowercase format. • %X Prints a number in hexadecimal (base 16) uppercase format.
-
flags: • Manage any combination of the following flags: ’-0.’ and the field minimum width under all conversions. • Manage all the following flags: ’# +’ (Yes, one of them is a space)
Question what is the meaning of '.' when there is no float conversion?
from manpage: the overall syntax for conversion specification is: %[$][flags][width][.precision][length modifier]conversion
- '-': overrides 0 if present, left justification in field boundary. this means everything right of number is filled with whitespaces. can have multiple '-' but this does not have any effect.
- '0': if also '-' is given '0' is ignored. pads d, i, o, u, x, X, a, A, e, E, f, F, g, and G with zeros
- '.': usually this is for precision with floats... for i, u, x, X this also pads by zero even in the presence of '-'
- 'x' and 'X': can only convert up to unsigned int.
- width: there must not be any flag between the conversion specifier and the width.
so, '-.10d' works. '-010d' only left justifies without padding by zero.
so a algorithm for deciding if we have valid, usable flags would be:
- check if first char after % is a '-'
- if next few digits are a valid unsigned int
...