Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
b529ed1e
Commit
b529ed1e
authored
Jun 26, 2008
by
Kenichi Handa
Browse files
(encode-coding-char): Fix for ASCII characters.
parent
a509862b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
22 deletions
+25
-22
lisp/international/mule-cmds.el
lisp/international/mule-cmds.el
+25
-22
No files found.
lisp/international/mule-cmds.el
View file @
b529ed1e
...
@@ -2805,29 +2805,32 @@ If there's no description string for VALUE, return nil."
...
@@ -2805,29 +2805,32 @@ If there's no description string for VALUE, return nil."
(defun encode-coding-char (char coding-system)
(defun encode-coding-char (char coding-system)
"Encode CHAR by CODING-SYSTEM and return the resulting string.
"Encode CHAR by CODING-SYSTEM and return the resulting string.
If CODING-SYSTEM can't safely encode CHAR, return nil."
If CODING-SYSTEM can't safely encode CHAR, return nil."
(let ((str1 (string-as-multibyte (string char)))
(let* ((str1 (string-as-multibyte (string char)))
(str2 (string-as-multibyte (string char char)))
(str2 (string-as-multibyte (string char char)))
(found (find-coding-systems-string str1))
enc1 enc2 i1 i2)
enc1 enc2 i1 i2)
(when (memq (coding-system-base coding-system)
(if (and (consp found)
(find-coding-systems-string str1))
(eq (car found) 'undecided))
;; We must find the encoded string of CHAR. But, just encoding
str1
;; CHAR will put extra control sequences (usually to designate
(when (memq (coding-system-base coding-system) found)
;; ASCII charset) at the tail if type of CODING is ISO 2022.
;; We must find the encoded string of CHAR. But, just encoding
;; To exclude such tailing bytes, we at first encode one-char
;; CHAR will put extra control sequences (usually to designate
;; string and two-char string, then check how many bytes at the
;; ASCII charset) at the tail if type of CODING is ISO 2022.
;; tail of both encoded strings are the same.
;; To exclude such tailing bytes, we at first encode one-char
;; string and two-char string, then check how many bytes at the
(setq enc1 (encode-coding-string str1 coding-system)
;; tail of both encoded strings are the same.
i1 (length enc1)
enc2 (encode-coding-string str2 coding-system)
(setq enc1 (encode-coding-string str1 coding-system)
i2 (length enc2))
i1 (length enc1)
(while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2))))
enc2 (encode-coding-string str2 coding-system)
(setq i1 (1- i1) i2 (1- i2)))
i2 (length enc2))
(while (and (> i1 0) (= (aref enc1 (1- i1)) (aref enc2 (1- i2))))
;; Now (substring enc1 i1) and (substring enc2 i2) are the same,
(setq i1 (1- i1) i2 (1- i2)))
;; and they are the extra control sequences at the tail to
;; exclude.
;; Now (substring enc1 i1) and (substring enc2 i2) are the same,
(substring enc2 0 i2))))
;; and they are the extra control sequences at the tail to
;; exclude.
(substring enc2 0 i2)))))
;; Backwards compatibility. These might be better with :init-value t,
;; Backwards compatibility. These might be better with :init-value t,
;; but that breaks loadup.
;; but that breaks loadup.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment