Lisp:在将八位字节流转换为具有格式错误字节的EUC-JP时,需要帮助从SBCL获得正确的行为
题
以下在这种特殊情况下不起作用,抱怨无论你给它什么都不是一个角色。
(handler-bind ((sb-int:character-coding-error
#'(lambda (c)
(invoke-restart 'use-value #\?))))
(sb-ext:octets-to-string *euc-jp* :external-format :euc-jp))
其中 * euc-jp *
是包含EUC-JP编码文本二进制的变量。
我也尝试过#\ KATAKANA_LETTER_NI
,而不是#\?并且还只是“”。到目前为止,没有任何工作。
非常感谢任何帮助!
编辑:要重现 * EUC-JP *
,请获取 http://blogs.yahoo.co.jp/akira_w0325/27287392.html 使用drakma。
解决方案
SBCL 1.0.18的 mb-util.lisp
中有一个表达式,如下所示:
(if code
(code-char code)
(decoding-error array pos (+ pos bytes) ,format
',malformed pos))
我对SBCL的内部结构不是很熟悉,但这看起来像个错误。结果返回一个字符,而替代方法返回一个字符串(无论你通过 USE-VALUE
给它什么,它总是通过 STRING
转换成一个字符串函数;参见 octets.lisp
中 DECODING-ERROR
的定义。
其他提示
它对我有用:
CL-USER> (handler-bind ((sb-int:character-coding-error
#'(lambda (c)
(declare (ignore c))
(invoke-restart 'use-value #\?))))
(sb-ext:octets-to-string (make-array '(16)
:element-type '(unsigned-byte 8)
:initial-contents '#(181 65 217 66 164 67 181 217 164 223 164 222 164 185 161 163))
:external-format :euc-jp))
"?A?B?C休みます。"
可能 * euc-jp *
不是a(vector(无符号字节8))?
不隶属于 StackOverflow