Re: Where did all the spaces come from?

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
  • Where did all the spaces come from?
    • Justin Jay Sako - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id MAA29376Fri, 12 Jun 1998 12:52:05 -0400 (EDT)
      • Graydon Hoare - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id NAA00549Fri, 12 Jun 1998 13:51:47 -0400 (EDT) <=
      • <Possible follow-ups>
      • W. Eliot Kimber - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id LAA04549Mon, 15 Jun 1998 11:53:34 -0400 (EDT)