titer6.nim 865 B

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