如何处理Common Lisp(SBCL)中的口音? [英] How to handle accents in Common Lisp (SBCL)?

查看:68
本文介绍了如何处理Common Lisp(SBCL)中的口音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是非常基本的,但是我不知道还有什么要问的.我正在尝试使用葡萄牙语编写的文件在SLIME REPL中处理一些文本信息,因此使用了很多重音符号-例如é,á,ô等.

That's probably very basic, but I didn't know where else to ask. I'm trying to process some text information in an SLIME REPL from a file that are written in Portuguese, hence uses lots of accents characters - such as é, á, ô, etc..

当我用英语处理文本时,我使用以下功能:

When I'm handling texts in English I use the following function:

(defun txt2list (name)
  (with-open-file (in name)
      (let ((res))
        (do ((line (read-line in nil nil)
                   (read-line in nil nil)))
        ((null line)
         (reverse res))
      (push line res))
    res)))

无法读取带重音符号的字符,并出现错误八位位组序列#(195)无法解码.".

that cannot read accented characters, giving the error "the octet sequence #(195) cannot be decoded.".

所以我的问题是:有没有一种方法可以自动操纵这些字符?可以将这些字符替换为不带重音的字母(á"变成"a"),或者简单地删除这些字符(cômodo"变成"cmodo"),无论是在读取之前还是在文件过程中在文件中完成阅读过程.

So my question is: Is there a way to manipulate those characters automatically? It's okay to replace those characters for the letter without the accent ('á' turns into 'a') or simply deleting such characters ('cômodo' turns into 'cmodo'), whether it is done in the file itself before reading or during the reading process.

推荐答案

您需要找出用于文件的文本编码.然后告诉WITH-OPEN-FILE使用正确的密码.

You would need to find out what text encoding is used for the file. Then tell WITH-OPEN-FILE to use the correct one.

请参阅SBCL手册:外部格式

See the SBCL manual: External Formats

示例:

 (with-open-file (stream pathname :external-format '(:utf-8 :replacement #\?))
   (read-line stream))

这篇关于如何处理Common Lisp(SBCL)中的口音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆