Open vlushn opened 3 years ago
This makes a lot of sense.
To me this looks like doing a re-haul of the format generator to have a proper parser for the format
string. We can use a parser-combinator like nom for this. We can then use standard Rust crates to do the heavy lifting (regex, string slicing etc.). A lot of this should be covered by https://docs.rs/regex/1.5.4/regex/.
A lot of this also seems upstreamable into dynfmt
- I've opened an issue there to see if there is any plan to implement this.
Currently, string formatter can:
same_as
truncate
This is a good start but not enough for a robust string manipulation mechanism. It would be great to have support for string slicing (i.e. take the first 5 characters or between the 7th and 10th character) and regex extraction (take the first capture group). For that we also need to think about what the format string language looks like.
Examples:
{name[2..]}
or{mac_addr[8..12]}
{ip4cidr@^[0-9]\.[0-9]\.[0-9].\[0-9]$@{2}}
to extract the third octetIt doesn't look like
dynfmt
currently supports more advanced formats so something might need to change there.