summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--doc/tut2.txt16
1 files changed, 9 insertions, 7 deletions
diff --git a/doc/tut2.txt b/doc/tut2.txt
index 4d8d0be15..3e10d172c 100644
--- a/doc/tut2.txt
+++ b/doc/tut2.txt
@@ -820,11 +820,12 @@ use the following snippet of code as the starting point:
     let
       inputString = readFile(cfgFilename)
     var
-      rawLines = split(inputString, {char(0x0a), char(0x0d)})
       source = ""
 
     result = initTable[string, string]()
-    for line in rawLines:
+    for line in inputString.splitLines:
+      # Ignore empty lines
+      if line.len < 1: continue
       var chunks = split(line, ',')
       if chunks.len != 2:
         quit("Input needs comma split values, got: " & line)
@@ -882,10 +883,11 @@ modified source code implementing the macro:
     let
       inputString = slurp(cfgFilename.strVal)
     var
-      rawLines = split(inputString, {char(0x0a), char(0x0d)})
       source = ""
 
-    for line in rawLines:
+    for line in inputString.splitLines:
+      # Ignore empty lines
+      if line.len < 1: continue
       var chunks = split(line, ',')
       if chunks.len != 2:
         error("Input needs comma split values, got: " & line)
@@ -1001,11 +1003,11 @@ macro:
   macro readCfgAndBuildAST(cfgFilename: string): stmt =
     let
       inputString = slurp(cfgFilename.strVal)
-    var
-      rawLines = split(inputString, {char(0x0a), char(0x0d)})
 
     result = newNimNode(nnkStmtList)
-    for line in rawLines:
+    for line in inputString.splitLines:
+      # Ignore empty lines
+      if line.len < 1: continue
       var chunks = split(line, ',')
       if chunks.len != 2:
         error("Input needs comma split values, got: " & line)
a id='n159' href='#n159'>159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196