Skip to content

replace naive unicode support with system-dependent in collapse-whitespa... #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions src/nox/xml-util.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -416,30 +416,20 @@
char)))

(defun collapse-whitespace (string)
;; new version with "poor man's Unicode support" :-(
"Trims and replaces multiple whitespace char occurences with a
single Space. Relies on the platform's unicode support."

;; see also https://github.com/lisp/de.setf.wilbur/issues/4
(labels ((collapse (mode old new)
(if old
(dsb (c &rest old) old
(cond ((zerop (logand (char-code c) #b10000000))
(if (whitespace-char-p c)
(collapse (if (eq mode :start) :start :white) old new)
(collapse :collect old
(if (eq mode :white)
(list* c #\Space new)
(cons c new)))))
((= (logand (char-code c) #b11100000) 192)
(collapse :collect (cdr old)
(if (eq mode :white)
(list* (car old) c #\Space new)
(list* (car old) c new))))
((= (logand (char-code c) #b11110000) 224)
(collapse :collect (cddr old)
(if (eq mode :white)
(list* (cadr old) (car old) c #\Space new)
(list* (cadr old) (car old) c new))))
(t
(error "Cannot decode this: ~S" (cons c old)))))
(concatenate 'string (nreverse new)))))
(dsb (c &rest old) old
(if (whitespace-char-p c)
(collapse (if (eq mode :start) :start :white) old new)
(collapse :collect old
(if (eq mode :white)
(list* c #\Space new)
(cons c new)))))
(concatenate 'string (nreverse new)))))
(declare (dynamic-extent #'collapse))
(collapse :start (coerce string 'list) nil)))

Expand Down