Step 6 of 6
Challenge: load a config
Put the pieces together in the kind of code every service has: a config loader that reports precise errors, because "invalid config" with no line number wastes everyone's time.
Your turn: write ConfigResult load_config(const std::string& text). The text has one key=value per line:
- blank lines and lines starting with
#are skipped - a line with no
=fails with"line N: missing =" - an empty key fails with
"line N: empty key" - a key seen twice fails with
"line N: duplicate key KEY" - otherwise every pair goes into
values
Lines are numbered from 1. Stop at the first error.