|
Subject: Re: Where did all the spaces come from? From: Graydon Hoare <graydon@xxxxxxxxxxxxx> Date: Fri, 12 Jun 1998 13:37:25 -0400 (EDT) |
On Fri, 12 Jun 1998, Justin Jay Sako wrote:
> Can anyone tell me why I receive all these spaces in my output (and how to get rid of them)? (This is just a test file I threw together)
Sure. Look at your input file. You're indenting your XML. The indentation
spacing is whitespace too. Jade is just preserving your whitespace for
you.
You can write a little dsssl function which collapses adjacent spaces if
you want.. it's not *too* hard. I think this should do it.
;; simple whitespace predicate. Might want to localize it.
(define (whitespace? ch)
(case ch
((#\space) #t)
((#\U-000A) #t) ;; LF
((#\U-000D) #t) ;; CR
((#\U-0009) #t) ;; VT
(else #f)))
;; trims whitespace-following-whitespace
(define (collapse-spaces str)
(let ((len (string-length str)))
(let loop ((pos 0)
(in-spaces #f))
(if (equal? pos len) "" ;; bottom out
(let ((ch (string-ref str pos)))
(if in-spaces
(loop (+ pos 1) (whitespace? ch))
(string-append (string ch)
(loop (+ pos 1) whitespace? ch))))))))
sigh. 1 page of scheme, 1 word of perl.. oh well. It's, uh, more elegant.
yeah. haven't tested that code but you get the drift.
-graydon
DSSSList info and archive: http://www.mulberrytech.com/dsssl/dssslist
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Where did all the spaces come from?, Justin Jay Sako | Thread | Re: Where did all the spaces come f, W. Eliot Kimber |
| Where did all the spaces come from?, Justin Jay Sako | Date | A Petition To Netscape and Microsof, Dan Hable |
| Month |