[xyzzy:03085] Re: 文字列を 1byte ごとに処理
- Subject: [xyzzy:03085] Re: 文字列を 1byte ごとに処理
- From: Tetsuya Kamei <kamei@xxxxxxxxxxxx>
- X-mailer: Denshin 8 Go V321.2b5
- X-yzzy-version: 0.0.0.95
服部さん、こんにちは。
Thu, 29 Jul 1999 23:30:52 +0900 の
[xyzzy:03084] 文字列を 1byte ごとに処理
への返事です.
| 文字列を1byteごとに処理するのはどうしたらいいのでしょう?
うーん、あまりいい方法はありませんね(^^;
(defun url-hexify-string (str)
(with-output-to-string (s)
(let ((f #'(lambda (char)
(if (or (char> char #\z)
(char< char #\-)
(char< #\Z char #\a)
(char< #\: char #\@))
(format s "~:@(%~2,'0x~)" (char-code char))
(write-char char s)))))
(dotimes (i (length str))
(let* ((char (svref str i))
(code (char-code char)))
(if (>= code 256)
(progn
(funcall f (code-char (ash code -8)))
(funcall f (code-char (logand code 255))))
(funcall f char)))))))
(defun url-hexify-string (str)
(with-output-to-string (s)
(setq str (si:make-string-chunk str))
(dotimes (i (- (si:chunk-size str) 1))
(let ((char (code-char (si:unpack-uint8 str i))))
(if (or (char> char #\z)
(char< char #\-)
(char< #\Z char #\a)
(char< #\: char #\@))
(format s "~:@(%~2,'0x~)" (char-code char))
(write-char char s))))))
--
亀井哲弥(Tetsuya Kamei)
kamei@xxxxxxxxxxxx/JCA00343@xxxxxxxxxxx