diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-31 11:39:17 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-31 14:17:45 -0700 |
commit | ea65968c79bf0709664081e4c116dee0d9c536ab (patch) | |
tree | d5020ad301052db98d873584565352089cbcbe7a /src/property/file.lisp | |
parent | 47aa65619025242b26cf3473efe25f88c24ae323 (diff) | |
download | consfigurator-ea65968c79bf0709664081e4c116dee0d9c536ab.tar.gz |
add & use WORDS, UNWORDS
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/file.lisp')
-rw-r--r-- | src/property/file.lisp | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/property/file.lisp b/src/property/file.lisp index 4af2e27..a54d38c 100644 --- a/src/property/file.lisp +++ b/src/property/file.lisp @@ -439,25 +439,23 @@ not NO-SOURCE and the corresponding member of ENTRIES is STRING= to either NO-SOURCE or \"PLACEHOLDER\", use the existing field value." (let ((unknown (list no-source "PLACEHOLDER")) (pending (make-hash-table :test #'equal))) - (flet ((fields (entry) - (remove "" (split-string entry) :test #'string=))) - (dolist (entry entries) - (setf (gethash (nth target (fields entry)) pending) entry)) - (map-file-lines - file - (lambda (lines) - (loop for line in lines - for line-fields = (fields line) - for line-source = (nth source line-fields) - and line-target = (nth target line-fields) - for entry = (when-let* ((entry (gethash line-target pending)) - (fields (fields entry))) - (when (and (member (nth source fields) - unknown :test #'string=) - (not (string= line-source no-source))) - (setf (nth source fields) line-source)) - (format nil "~{~A~^ ~}" fields)) - if entry - collect it into accum and do (remhash line-target pending) - else collect line into accum - finally (return (nconc accum (hash-table-values pending))))))))) + (dolist (entry entries) + (setf (gethash (nth target (words entry)) pending) entry)) + (map-file-lines + file + (lambda (lines) + (loop for line in lines + for line-fields = (words line) + for line-source = (nth source line-fields) + and line-target = (nth target line-fields) + for entry = (when-let* ((entry (gethash line-target pending)) + (fields (words entry))) + (when (and (member (nth source fields) + unknown :test #'string=) + (not (string= line-source no-source))) + (setf (nth source fields) line-source)) + (format nil "~{~A~^ ~}" fields)) + if entry + collect it into accum and do (remhash line-target pending) + else collect line into accum + finally (return (nconc accum (hash-table-values pending)))))))) |