titer6.nim 860 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: "000"
  3. """
  4. # Test iterator with more than 1 yield statement
  5. import strutils
  6. iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[
  7. token: string, isSep: bool] =
  8. var i = 0
  9. while i < s.len:
  10. var j = i
  11. if s[j] in seps:
  12. while j < s.len and s[j] in seps: inc(j)
  13. if j > i:
  14. yield (substr(s, i, j-1), true)
  15. else:
  16. while j < s.len and s[j] notin seps: inc(j)
  17. if j > i:
  18. yield (substr(s, i, j-1), false)
  19. i = j
  20. for word, isSep in tokenize2("ta da", WhiteSpace):
  21. var titer2TestVar = 0
  22. stdout.write(titer2TestVar)
  23. proc wordWrap2(s: string, maxLineWidth = 80,
  24. splitLongWords = true,
  25. seps: set[char] = Whitespace,
  26. newLine = "\n"): string =
  27. result = ""
  28. for word, isSep in tokenize2(s, seps):
  29. var w = 0
  30. stdout.write "\n"