Hi all,
I would like to teach cl-irc about the goodness of external-formats, and because irc doesn't let users specify which external format to use, I need something as flexible as flexi-streams (-:
So, once I've read an irc command (as a "line" of latin-1 characters), I'd like to convert it to text that looks the least insane, which is why my code tries several external-formats in a row and returns as soon as it found one that doesn't throw an error:
(defun try-decode-line (line external-formats) (loop for external-format in external-formats for decoded = nil for error = nil do (multiple-value-setq (decoded error) (ignore-errors (flexi-streams:with-input-from-sequence (in line) (setf (flexi-streams:flexi-stream-external-format in) external-format) (read-line in)))) do (format t "~&tried ~s: ~S~% error: ~A~%" external-format decoded error) if decoded do (return decoded)))
Try it with:
(try-decode-line "foo" '((:UTF-8 :EOL-STYLE :LF) (:LATIN-1 :EOL-STYLE :LF)))
(alternatively, (map 'vector #'char-code "foo") and with (list (make-external-format...)) calls) And for each of the external formats, I get:
There is no applicable method for the generic function #<STANDARD-GENERIC-FUNCTION (SETF FLEXI-STREAMS:FLEXI-STREAM-EXTERNAL-FORMAT) (2)> when called with arguments ((:UTF-8 :EOL-STYLE :LF) #<FLEXI-STREAMS::VECTOR-INPUT-STREAM {ABEFA91}>).
Hrmpf! Am I abusing flexi-streams too much or is that a bug? How should one read externally-formatted data from an in-memory stream, anyway?
And are string-backed in-memory streams even allowed? How to specify the internal external format for them? (-:
Thanks for your time and for developing flexi-streams. In return, I hope to be able to buy you a beverage of your choice in Hamburg (-:
Cheers,