3 ms·
then replace all the line breaks, <, < and single quotes with "," split it on the double quotes(!?) have some stupid ip validation like a minimum length and c
by hokus 9y ago
then replace all the line breaks, <, < and single quotes with ","
split it on the double quotes(!?)
have some stupid ip validation like a minimum length and chars used (trim included ofc)
and voilà! Now it parses line break or comma separated as well as json, xml, html. Can throw any crap at it, if the crap has anything that looks like ip addresses wrapped in quotes and or line breaks it will work.
Make the ip validation better for even better results.
- userbinator 9y agoThe whole point is to not have to do all that extra work, because you make your input file format simple enough. Just read a line, take the first (or only) whitespace-separated part and feed it to inet_addr() or whatever networking function you use that takes hostnames and uses them. If it's invalid, it will tell you and you can print the offending one. No need to do anything extra. My experience has taught me that it's fragile and stupid to do any sort of "validation" by reimplementing parts of lower layers. Need IPv6 support, or hostnames instead of IPs? If you hardcoded validation for IPv4 only, then you have to do extra work to either add that duplication, or (even better) get rid of the code completely. If you let the lower layers do the work, the additional functionalty is free. (And if the data is invalid to the lower layer, it will complain for you.)