LISP Scheme Part4
■ このスレッドは過去ログ倉庫に格納されています
0677デフォルトの名無しさん
NGNG(define (split-quote-string s)
(let loop ((si 0)(i 0)(quote? #f)(r '()))
(if (< i (string-length s))
(cond
((char=? #\" (string-ref s i))
(loop si (+ i 1) (not quote?) r))
((and (not quote?) (memv (string-ref s i) '(#\tab #\space #\newline)))
(loop (+ i 1) (+ i 1) quote? (if (= si i) r (cons (substring s si i) r))))
(else (loop si (+ i 1) quote? r)))
(reverse(if(= si i)r(cons (substring s si i) r))))))
(define (split-tag-string s)
(let ((tag (split-quote-string s)))
(if (nlength? 2 tag)
(cons (string->symbol (car tag)) (cdr tag))
(string->symbol (car tag)))))
>(split-tag-string "A HREF=\"http://\" target=\"_blank\"" )
=>(A "HREF=\"http://\"" "target=\"_blank\"")
タグだけシンボルにしてみました。
この辺はperlなら数行で出来てしまえるかも
■ このスレッドは過去ログ倉庫に格納されています