X-Git-Url: http://cgit.sxemacs.org/?p=gnus;a=blobdiff_plain;f=lisp%2Futf7.el;h=c2f8c0e50872fb4df3d2a4c17b6a4d4be9e0301c;hp=d2666ebac2b95630a10c22ca376df2937f898c9a;hb=4fe932c9ab0714252bb9a6de65b139026c41b3ac;hpb=e2c9efb05a1ae9e65fd40bab80466da331f3981b diff --git a/lisp/utf7.el b/lisp/utf7.el index d2666ebac..c2f8c0e50 100644 --- a/lisp/utf7.el +++ b/lisp/utf7.el @@ -1,7 +1,6 @@ -;;; utf7.el --- UTF-7 encoding/decoding for Emacs -*-coding: iso-8859-1;-*- +;;; utf7.el --- UTF-7 encoding/decoding for Emacs -*-coding: utf-8;-*- -;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, -;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +;; Copyright (C) 1999-2015 Free Software Foundation, Inc. ;; Author: Jon K Hellan ;; Maintainer: bugs@gnus.org @@ -53,10 +52,10 @@ ;; necessary coding system. The code below doesn't seem to DTRT ;; generally. E.g.: ;; -;; (utf7-encode "a+£") +;; (utf7-encode "a+£") ;; => "a+ACsAow-" ;; -;; $ echo "a+£"|iconv -f iso-8859-1 -t utf-7 +;; $ echo "a+£"|iconv -f utf-8 -t utf-7 ;; a+-+AKM ;; ;; -- fx @@ -78,7 +77,7 @@ (defconst utf7-utf-16-coding-system (cond ((mm-coding-system-p 'utf-16-be-no-signature) ; Mule-UCS 'utf-16-be-no-signature) - ((and (mm-coding-system-p 'utf-16-be) ; Emacs 21.3, Emacs 22 + ((and (mm-coding-system-p 'utf-16-be) ; Emacs ;; Avoid versions with BOM. (= 2 (length (encode-coding-string "a" 'utf-16-be)))) 'utf-16-be) @@ -112,7 +111,7 @@ Use IMAP modification if FOR-IMAP is non-nil." (skip-chars-forward not-direct-encoding-chars))) (if (and (= fc esc-char) (= run-length 1)) ; Lone esc-char? - (delete-backward-char 1) ; Now there's one too many + (delete-char -1) ; Now there's one too many (utf7-fragment-encode p (point) for-imap)) (insert "-"))))))) @@ -153,7 +152,7 @@ Use IMAP modification if FOR-IMAP is non-nil." (save-excursion (utf7-fragment-decode p (point) for-imap) (goto-char p) - (delete-backward-char 1))))))))) + (delete-char -1))))))))) (defun utf7-fragment-decode (start end &optional for-imap) "Decode base64 encoded fragment from START to END of UTF-7 text in buffer. @@ -205,30 +204,28 @@ Characters are in raw byte pairs in narrowed buffer." (mm-decode-coding-region (point-min) (point-max) 'iso-8859-1) (mm-enable-multibyte)) +;;;###autoload (defun utf7-encode (string &optional for-imap) "Encode UTF-7 STRING. Use IMAP modification if FOR-IMAP is non-nil." (if (and (coding-system-p 'utf-7) (coding-system-p 'utf-7-imap)) ;; Emacs 23 with proper support for IMAP (encode-coding-string string (if for-imap 'utf-7-imap 'utf-7)) - (let ((default-enable-multibyte-characters t)) - (with-temp-buffer - (insert string) - (utf7-encode-internal for-imap) - (buffer-string))))) + (mm-with-multibyte-buffer + (insert string) + (utf7-encode-internal for-imap) + (buffer-string)))) (defun utf7-decode (string &optional for-imap) "Decode UTF-7 STRING. Use IMAP modification if FOR-IMAP is non-nil." (if (and (coding-system-p 'utf-7) (coding-system-p 'utf-7-imap)) ;; Emacs 23 with proper support for IMAP (decode-coding-string string (if for-imap 'utf-7-imap 'utf-7)) - (let ((default-enable-multibyte-characters nil)) - (with-temp-buffer - (insert string) - (utf7-decode-internal for-imap) - (mm-enable-multibyte) - (buffer-string))))) + (mm-with-unibyte-buffer + (insert string) + (utf7-decode-internal for-imap) + (mm-enable-multibyte) + (buffer-string)))) (provide 'utf7) -;; arch-tag: 96078b55-85c7-4161-aed2-932c24b282c7 ;;; utf7.el ends here