Modifies example to use splitLines.
This commit is contained in:
parent
38eb67de83
commit
c3e7a970c6
1 changed files with 9 additions and 7 deletions
16
doc/tut2.txt
16
doc/tut2.txt
|
|
@ -820,11 +820,12 @@ use the following snippet of code as the starting point:
|
||||||
let
|
let
|
||||||
inputString = readFile(cfgFilename)
|
inputString = readFile(cfgFilename)
|
||||||
var
|
var
|
||||||
rawLines = split(inputString, {char(0x0a), char(0x0d)})
|
|
||||||
source = ""
|
source = ""
|
||||||
|
|
||||||
result = initTable[string, string]()
|
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, ',')
|
var chunks = split(line, ',')
|
||||||
if chunks.len != 2:
|
if chunks.len != 2:
|
||||||
quit("Input needs comma split values, got: " & line)
|
quit("Input needs comma split values, got: " & line)
|
||||||
|
|
@ -882,10 +883,11 @@ modified source code implementing the macro:
|
||||||
let
|
let
|
||||||
inputString = slurp(cfgFilename.strVal)
|
inputString = slurp(cfgFilename.strVal)
|
||||||
var
|
var
|
||||||
rawLines = split(inputString, {char(0x0a), char(0x0d)})
|
|
||||||
source = ""
|
source = ""
|
||||||
|
|
||||||
for line in rawLines:
|
for line in inputString.splitLines:
|
||||||
|
# Ignore empty lines
|
||||||
|
if line.len < 1: continue
|
||||||
var chunks = split(line, ',')
|
var chunks = split(line, ',')
|
||||||
if chunks.len != 2:
|
if chunks.len != 2:
|
||||||
error("Input needs comma split values, got: " & line)
|
error("Input needs comma split values, got: " & line)
|
||||||
|
|
@ -1001,11 +1003,11 @@ macro:
|
||||||
macro readCfgAndBuildAST(cfgFilename: string): stmt =
|
macro readCfgAndBuildAST(cfgFilename: string): stmt =
|
||||||
let
|
let
|
||||||
inputString = slurp(cfgFilename.strVal)
|
inputString = slurp(cfgFilename.strVal)
|
||||||
var
|
|
||||||
rawLines = split(inputString, {char(0x0a), char(0x0d)})
|
|
||||||
|
|
||||||
result = newNimNode(nnkStmtList)
|
result = newNimNode(nnkStmtList)
|
||||||
for line in rawLines:
|
for line in inputString.splitLines:
|
||||||
|
# Ignore empty lines
|
||||||
|
if line.len < 1: continue
|
||||||
var chunks = split(line, ',')
|
var chunks = split(line, ',')
|
||||||
if chunks.len != 2:
|
if chunks.len != 2:
|
||||||
error("Input needs comma split values, got: " & line)
|
error("Input needs comma split values, got: " & line)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue