guile-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ugh


From: thi
Subject: ugh
Date: Thu, 5 Apr 2001 15:34:47 -0700

bitch moan bitch moan....

thi


_________________________________________________
(define (read-pgarray-1 objectifier port)
  ;; ugh, i hate parsing...  the right thing to do would be find out if
  ;; postgres supports (easily!) parameterizable array output formatting.
  ;; then, we could just specify using "()" instead of "{}" and space instead
  ;; of comma, and this proc becomes a simple objectifier walk over `read'
  ;; output.  on the bright side, maybe this proc can go into official guile
  ;; distribution (w/ some tweaks).
  (let ((next (lambda () (peek-char port))))
    (let loop ((c (next)) (acc '()))
      (cond ((eof-object? c) (reverse acc))                     ;;; retval
            ((char=? #\} c) (read-char port) (reverse acc))     ;;; retval
            ((char=? #\{ c)
             (read-char port)
             (let ((sub (read-pgarray-1 objectifier port)))
               (loop (next) (cons sub acc))))
            ((char=? #\" c)
             (let ((string (read port)))
               (loop (next) (cons (objectifier string) acc))))
            ((char=? #\, c)
             (read-char port)
             (loop (next) acc))
            (else (let ((o (let iloop ((ic (read-char port)) (iacc '()))
                             (case ic
                               ((#\} #\,)
                                (unread-char ic port)
                                (objectifier (list->string (reverse iacc))))
                               (else
                                (iloop (read-char port) (cons ic iacc)))))))
                    (loop (next) (cons o acc))))))))

(define (read-array-string objectifier string)
  (call-with-input-string string
                          (lambda (port)
                            (read-char port)
                            (read-pgarray-1 objectifier port))))

guile> (read-array-string string-upcase "{\"abc\",\"def\"}")
("ABC" "DEF")
guile> (read-array-string string->number "{1,{2,3},{4,{5,6},7,{8,{9},10}},11}")
(1 (2 3) (4 (5 6) 7 (8 (9) 10)) 11)
guile> (read-array-string error "{}")
()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]