summary refs log tree commit diff stats
path: root/tests/iter/titer6.nim
blob: 69a10d8688990cad8c581770df071c216f242ef3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
discard """
  output: "000"
"""
# Test iterator with more than 1 yield statement

import strutils

iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[
  token: string, isSep: bool] =
  var i = 0
  while i < s.len:
    var j = i
    if s[j] in seps:
      while j < s.len and s[j] in seps: inc(j)
      if j > i:
        yield (substr(s, i, j-1), true)
    else:
      while j < s.len and s[j] notin seps: inc(j)
      if j > i:
        yield (substr(s, i, j-1), false)
    i = j

for word, isSep in tokenize2("ta da", WhiteSpace):
  var titer2TestVar = 0
  stdout.write(titer2TestVar)

proc wordWrap2(s: string, maxLineWidth = 80,
               splitLongWords = true,
               seps: set[char] = Whitespace,
               newLine = "\n"): string  =
  result = ""
  for word, isSep in tokenize2(s, seps):
    var w = 0

stdout.write "\n"