return to first page linux journal archive
keywordscontents

Listing 4. C-style chomp function

(define (chomp string)
  (substring string 0
             ;; start at the end of the string and work backward
	     (let loop ((len (string-length string)))
	     ;; recurse until we have the number of the last
	     ;; non-newline character
	     (if (and (> len 0)
                      (lineterm? (string-ref string (- len 1))))
		 (loop (- len 1))
		 len))))
Back to article