1
0

simple-tokenize.cpp 863 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "simple-tokenize.h"
  2. std::vector<std::string> simple_tokenize(const std::string & input) {
  3. std::vector<std::string> result;
  4. std::string current;
  5. for (size_t i = 0; i < input.size(); i++) {
  6. switch (input[i]) {
  7. case ' ':
  8. case '\n':
  9. case '\t':
  10. case '{':
  11. case '}':
  12. case ',':
  13. case '[':
  14. case '"':
  15. case ']':
  16. case '.':
  17. case '<':
  18. case '>':
  19. case '=':
  20. case '/':
  21. if (!current.empty()) {
  22. result.push_back(current);
  23. current.clear();
  24. }
  25. default:;
  26. }
  27. current += input[i];
  28. }
  29. if (!current.empty()) {
  30. result.push_back(current);
  31. }
  32. return result;
  33. }