From 88eba9077679a803bb5bcc62c72b3c734dd12a66 Mon Sep 17 00:00:00 2001 From: Dimitri Fontaine Date: Tue, 17 Jun 2014 17:24:07 +0200 Subject: [PATCH] Handle "ragged right" fixed width files, fix #82. --- src/sources/fixed.lisp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sources/fixed.lisp b/src/sources/fixed.lisp index 3274f4d..d623458 100644 --- a/src/sources/fixed.lisp +++ b/src/sources/fixed.lisp @@ -34,9 +34,12 @@ (defun parse-row (fixed-cols-specs line) "Parse a single line of FIXED input file and return a row of columns." - (loop :for opts :in fixed-cols-specs + (loop :with len := (length line) + :for opts :in fixed-cols-specs :collect (destructuring-bind (&key start length &allow-other-keys) opts - (subseq line start (+ start length))))) + (let ((end (+ start length))) + (when (<= end len) + (subseq line start end)))))) (defmethod map-rows ((fixed copy-fixed) &key process-row-fn) "Load data from a text file in Fixed Columns format.