2011-05-24 71 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