开发者

How can I read a string with problematic modifiers?

I cannot read a string like "D\xC3\xA9cada", Década, on Emacs. Apparently, it tries to find the character corresponding to the \xA9cada, valid hex, and fails to find it, returning the following error:

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

Are there any ways to limit the reader to find the modifier in the first two characters beyond the x, or general workarounds? Replacing the '\xA9' for the '\251' would work in this case, but might not in the string '\xA9000'.

Thanks!


EDIT: In the end, I had to change the string generating program to take this into account. Every sequence would be appended with '\ '. In ruby: puts string.gsub(/(\开发者_Go百科\x[0-9A-F][0-9A-F])([0-9A-Fa-f])/,'\1\\\\ \2')


See the 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜