Hi, Back in nim after a break and trying to use it to create a svg sprite document from a directory full of svgs.
for file in walkDir(currentDir):
if file.kind == pcFile:
filename = splitFile(file.path)
filesize = getFileSize(file.path)
if filename.ext == ".svg":
fs = newFileStream(file.path, fmRead)
readBuffer = fs.readStr(filesize.int)
echo "processing: " & filename.name
outText.add(readBuffer.string.replacef(re("(.*?\\s*?)*?preserve\\\">((.*?\\s*?)*)</svg>", {reMultiLine}), "<symbol id=\"" & filename.name & "\" viewBox=\"0 0 96 96\">$2</symbol>"))
fs.close();
The line breaking is when I concat the new text to the outText variable. But only on the second file/loop. No error message but a crash in runtime.
It doesnt matter if I replace it with something like:
echo readBuffer.string.replacef(re("(.*?\\s*?)*?preserve\\\">((.*?\\s*?)*)</svg>", {reMultiLine}), "foo")
So what am I totally not understanding?SOLVED:
Seems that pcre croaks on the amount of capture groups (even if I add ?: no ignore it). If I changed the code to:
outText.add(readBuffer.string.replacef(re(".*?preserve\\\">(.*?)</svg>", {reMultiLine, reDotAll}), "<symbol id=\"" & filename.name & "\" viewBox=\"0 0 96 96\">$1</symbol>"))
Things work just fine.