No description
Find a file
2019-08-24 12:00:12 +10:00
.gitignore Create .gitignore 2015-09-21 21:20:28 +10:00
LICENSE Initial commit 2015-09-21 20:40:34 +10:00
parsefixed.nim Update parsefixed.nim 2019-08-24 11:56:54 +10:00
parsefixed.nimble Update parsefixed.nimble 2019-08-24 11:57:21 +10:00
README.md Update README.md 2019-08-24 12:00:12 +10:00

parsefixed

Nim module to parse fixed-width fields within lines of text (complementary to parsecsv).

It is line based (terminating in CR, LF, or CR LF), so does not support multi-line field splitting.

Example

import os, parsefixed, streams

var 
  s = newFileStream(paramStr(1), fmRead)
  x: FwParser

if s == nil:
  quit("[Errpr] Cannot open the file: " & paramStr(1))

# widths: 9,6,10,... (not starting positions)
x.open(s, paramStr(1), @[9, 6, 10, 6, 7, 7, 35])

while x.readRow():
 echo "new row: "
 for val in items(x.row):
   echo "##", val, "##"
x.close()

Rationale

awk provides two main text processing approaches: regex based field splitting, and fixed-width field splitting.

The Nim pure library, parsecsv, handles non-regex (but delimited) field splitting.

parsefixed is for fixed-width field splitting.