I'm working on a script that needs to decode some markup in
rtf, as documented here, the escape sequence
\' followed by hex digits specifies a character by numeric code, with the catch that this is not a Unicode code point but a character in the
Windows-1252 character set (at least in the files I'm dealing with).
So the question:
What is the cleanest way to convert a numeric code in a different character set to a Emacs multibyte character or string. Please note that I would like to avoid converting the whole file; I only want to convert a sequence of numeric codes in one encoding (
Windows-1252) to an equivalent sequence in another one.
The following code more or less works but seems needlessly verbose and wasteful:
(defun convert-rtf-byte (byte) (let ((file (make-temp-file "rtf"))) (with-temp-file file (insert (unibyte-string byte)) (setq coding-system-for-write 'no-conversion)) (with-temp-buffer (let ((coding-system-for-read 'cp1252)) (insert-file-contents file) (buffer-substring-no-properties (point-min) (point-max))))))