2011-05-24 74 views
1

我无法在Emacs上读取像"D\xC3\xA9cada"Década这样的字符串。显然,它试图找到对应\xA9cada,有效的十六进制字符,并没有找到它,返回以下错误:如何读取有问题修饰符的字符串?

ELISP> "D\xC3\xA9cada" 
*** Read error *** Invalid modifier in string 

有什么方法来限制读者发现前两个修饰语超出x的字符或一般解决方法?在这种情况下,替换'\ xA9'作为'\ 251'将起作用,但可能不会出现在字符串'\ xA9000'中。

谢谢!


编辑:最后,我不得不改变串生成程序,考虑到这一点。每个序列都会附加'\'。在红宝石:puts string.gsub(/(\\x[0-9A-F][0-9A-F])([0-9A-Fa-f])/,'\1\\\\ \2')

回答

2

Emacs Lisp manual

You can also represent a multibyte non-ASCII character with its character code: use a hex escape, ‘\xnnnnnnn’, with as many digits as necessary. (Multibyte non-ASCII character codes are all greater than 256.) Any character which is not a valid hex digit terminates this construct. If the next character in the string could be interpreted as a hex digit, write ‘\ ’ (backslash and space) to terminate the hex escape—for example, ‘\x8e0\ ’ represents one character, ‘a’ with grave accent. ‘\ ’ in a string constant is just like backslash-newline; it does not contribute any character to the string, but it does terminate the preceding hex escape.
+0

所以这是一个功能,而不是一个错误:d – konr 2011-05-24 23:11:24