Mercurial > emacs
comparison lisp/gnus/mm-util.el @ 90143:146c086df160
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-37
Merge from emacs--cvs-trunk--0
Patches applied:
* emacs--cvs-trunk--0 (patch 241-257)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 59-65)
- Update from CVS
- Merge from emacs--cvs-trunk--0
- (mm-string-to-multibyte): Use Gnus trunk definition.
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 14 Apr 2005 05:03:52 +0000 |
parents | 4da4a09e8b1b 6cf26dc690b2 |
children | 01137c1fdbe9 |
comparison
equal
deleted
inserted
replaced
90142:627771f44771 | 90143:146c086df160 |
---|---|
55 prompt | 55 prompt |
56 (mapcar (lambda (e) (list (symbol-name (car e)))) | 56 (mapcar (lambda (e) (list (symbol-name (car e)))) |
57 mm-mime-mule-charset-alist) | 57 mm-mime-mule-charset-alist) |
58 nil t)))) | 58 nil t)))) |
59 (subst-char-in-string | 59 (subst-char-in-string |
60 . (lambda (from to string) ;; stolen (and renamed) from nnheader.el | 60 . (lambda (from to string &optional inplace) |
61 "Replace characters in STRING from FROM to TO." | 61 ;; stolen (and renamed) from nnheader.el |
62 (let ((string (substring string 0)) ;Copy string. | 62 "Replace characters in STRING from FROM to TO. |
63 Unless optional argument INPLACE is non-nil, return a new string." | |
64 (let ((string (if inplace string (copy-sequence string))) | |
63 (len (length string)) | 65 (len (length string)) |
64 (idx 0)) | 66 (idx 0)) |
65 ;; Replace all occurrences of FROM with TO. | 67 ;; Replace all occurrences of FROM with TO. |
66 (while (< idx len) | 68 (while (< idx len) |
67 (when (= (aref string idx) from) | 69 (when (= (aref string idx) from) |
68 (aset string idx to)) | 70 (aset string idx to)) |
69 (setq idx (1+ idx))) | 71 (setq idx (1+ idx))) |
70 string))) | 72 string))) |
71 (string-as-unibyte . identity) | 73 (string-as-unibyte . identity) |
72 (string-make-unibyte . identity) | 74 (string-make-unibyte . identity) |
75 ;; string-as-multibyte often doesn't really do what you think it does. | |
76 ;; Example: | |
77 ;; (aref (string-as-multibyte "\201") 0) -> 129 (aka ?\201) | |
78 ;; (aref (string-as-multibyte "\300") 0) -> 192 (aka ?\300) | |
79 ;; (aref (string-as-multibyte "\300\201") 0) -> 192 (aka ?\300) | |
80 ;; (aref (string-as-multibyte "\300\201") 1) -> 129 (aka ?\201) | |
81 ;; but | |
82 ;; (aref (string-as-multibyte "\201\300") 0) -> 2240 | |
83 ;; (aref (string-as-multibyte "\201\300") 1) -> <error> | |
84 ;; Better use string-to-multibyte or encode-coding-string. | |
85 ;; If you really need string-as-multibyte somewhere it's usually | |
86 ;; because you're using the internal emacs-mule representation (maybe | |
87 ;; because you're using string-as-unibyte somewhere), which is | |
88 ;; generally a problem in itself. | |
89 ;; Here is an approximate equivalence table to help think about it: | |
90 ;; (string-as-multibyte s) ~= (decode-coding-string s 'emacs-mule) | |
91 ;; (string-to-multibyte s) ~= (decode-coding-string s 'binary) | |
92 ;; (string-make-multibyte s) ~= (decode-coding-string s locale-coding-system) | |
73 (string-as-multibyte . identity) | 93 (string-as-multibyte . identity) |
94 (string-to-multibyte | |
95 . (lambda (string) | |
96 "Return a multibyte string with the same individual chars as string." | |
97 (mapconcat | |
98 (lambda (ch) (mm-string-as-multibyte (char-to-string ch))) | |
99 string ""))) | |
74 (multibyte-string-p . ignore) | 100 (multibyte-string-p . ignore) |
75 ;; It is not a MIME function, but some MIME functions use it. | 101 ;; It is not a MIME function, but some MIME functions use it. |
76 (make-temp-file . (lambda (prefix &optional dir-flag) | 102 (make-temp-file . (lambda (prefix &optional dir-flag) |
77 (let ((file (expand-file-name | 103 (let ((file (expand-file-name |
78 (make-temp-name prefix) | 104 (make-temp-name prefix) |
151 "Return non-nil if CS is a symbol naming a coding system. | 177 "Return non-nil if CS is a symbol naming a coding system. |
152 In XEmacs, also return non-nil if CS is a coding system object. | 178 In XEmacs, also return non-nil if CS is a coding system object. |
153 If CS is available, return CS itself in Emacs, and return a coding | 179 If CS is available, return CS itself in Emacs, and return a coding |
154 system object in XEmacs." | 180 system object in XEmacs." |
155 (if (fboundp 'find-coding-system) | 181 (if (fboundp 'find-coding-system) |
156 (find-coding-system cs) | 182 (and cs (find-coding-system cs)) |
157 (if (fboundp 'coding-system-p) | 183 (if (fboundp 'coding-system-p) |
158 (when (coding-system-p cs) | 184 (when (coding-system-p cs) |
159 cs) | 185 cs) |
160 ;; Is this branch ever actually useful? | 186 ;; Is this branch ever actually useful? |
161 (car (memq cs (mm-get-coding-system-list)))))) | 187 (car (memq cs (mm-get-coding-system-list)))))) |
876 ;; Fixme: This doesn't look useful where it's used. | 902 ;; Fixme: This doesn't look useful where it's used. |
877 (if (fboundp 'detect-coding-region) | 903 (if (fboundp 'detect-coding-region) |
878 (defun mm-detect-coding-region (start end) | 904 (defun mm-detect-coding-region (start end) |
879 "Like `detect-coding-region' except returning the best one." | 905 "Like `detect-coding-region' except returning the best one." |
880 (let ((coding-systems | 906 (let ((coding-systems |
881 (detect-coding-region (point) (point-max)))) | 907 (detect-coding-region start end))) |
882 (or (car-safe coding-systems) | 908 (or (car-safe coding-systems) |
883 coding-systems))) | 909 coding-systems))) |
884 (defun mm-detect-coding-region (start end) | 910 (defun mm-detect-coding-region (start end) |
885 (let ((point (point))) | 911 (let ((point (point))) |
886 (goto-char start) | 912 (goto-char start) |
900 cs))) | 926 cs))) |
901 | 927 |
902 | 928 |
903 (provide 'mm-util) | 929 (provide 'mm-util) |
904 | 930 |
905 ;;; arch-tag: 94dc5388-825d-4fd1-bfa5-2100aa351238 | 931 ;; arch-tag: 94dc5388-825d-4fd1-bfa5-2100aa351238 |
906 ;;; mm-util.el ends here | 932 ;;; mm-util.el ends here |