scan.h 459 B

12345678910111213141516171819202122
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. template <bool addAll, char sep, char sepKeyVal, class F>
  4. static inline void ScanKeyValue(TStringBuf s, F&& f) {
  5. TStringBuf key, val;
  6. while (!s.empty()) {
  7. val = s.NextTok(sep);
  8. if (val.empty()) {
  9. continue; // && case
  10. }
  11. key = val.NextTok(sepKeyVal);
  12. if (addAll || val.IsInited()) {
  13. f(key, val); // includes empty keys
  14. }
  15. }
  16. }