delim_string_iter.cpp 1006 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "delim_string_iter.h"
  2. //
  3. // TKeyValueDelimStringIter
  4. //
  5. void TKeyValueDelimStringIter::ReadKeyAndValue() {
  6. TStringBuf currentToken(*DelimIter);
  7. size_t pos = currentToken.find('=');
  8. if (pos == TString::npos) {
  9. ChunkValue.Clear();
  10. ChunkKey = currentToken;
  11. } else {
  12. ChunkKey = currentToken.SubStr(0, pos);
  13. ChunkValue = currentToken.SubStr(pos + 1);
  14. }
  15. }
  16. TKeyValueDelimStringIter::TKeyValueDelimStringIter(const TStringBuf str, const TStringBuf delim)
  17. : DelimIter(str, delim)
  18. {
  19. if (DelimIter.Valid())
  20. ReadKeyAndValue();
  21. }
  22. bool TKeyValueDelimStringIter::Valid() const {
  23. return DelimIter.Valid();
  24. }
  25. TKeyValueDelimStringIter& TKeyValueDelimStringIter::operator++() {
  26. ++DelimIter;
  27. if (DelimIter.Valid())
  28. ReadKeyAndValue();
  29. return *this;
  30. }
  31. const TStringBuf& TKeyValueDelimStringIter::Key() const {
  32. return ChunkKey;
  33. }
  34. const TStringBuf& TKeyValueDelimStringIter::Value() const {
  35. return ChunkValue;
  36. }