summaryrefslogtreecommitdiff
path: root/lisp/select.el
diff options
context:
space:
mode:
authorKaroly Lorentey <lorentey@elte.hu>2006-12-03 12:25:18 +0000
committerKaroly Lorentey <lorentey@elte.hu>2006-12-03 12:25:18 +0000
commitd6e01aa592f7326dffeafa6e97180a1cc39fe7ea (patch)
tree5a22b785cfee1d77d6452607450a12ca82eeecd3 /lisp/select.el
parent14bcc1e098410087a837313e2fc822319ff2e8ca (diff)
parent4975e69596a64247e8995d1ff9084b98a9a5ed0d (diff)
downloademacs-d6e01aa592f7326dffeafa6e97180a1cc39fe7ea.tar.gz
emacs-d6e01aa592f7326dffeafa6e97180a1cc39fe7ea.tar.bz2
emacs-d6e01aa592f7326dffeafa6e97180a1cc39fe7ea.zip
Merged from emacs@sv.gnu.org.
Patches applied: * emacs@sv.gnu.org/emacs--devo--0--patch-479 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-480 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-481 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-482 Merge from gnus--rel--5.10 * emacs@sv.gnu.org/emacs--devo--0--patch-483 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-484 Update from CVS * emacs@sv.gnu.org/emacs--devo--0--patch-485 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-153 Merge from emacs--devo--0 * emacs@sv.gnu.org/gnus--rel--5.10--patch-154 Update from CVS * emacs@sv.gnu.org/gnus--rel--5.10--patch-155 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-585
Diffstat (limited to 'lisp/select.el')
-rw-r--r--lisp/select.el44
1 files changed, 39 insertions, 5 deletions
diff --git a/lisp/select.el b/lisp/select.el
index cbdeaf12fe3..9b711ee1d7f 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -152,6 +152,41 @@ Cut buffers are considered obsolete; you should use selections instead."
;;; Every selection type that Emacs handles is implemented this way, except
;;; for TIMESTAMP, which is a special case.
+(eval-when-compile (require 'ccl))
+
+(define-ccl-program ccl-check-utf-8
+ '(0
+ ((r0 = 1)
+ (loop
+ (read-if (r1 < #x80) (repeat)
+ ((r0 = 0)
+ (if (r1 < #xC2) (end))
+ (read r2)
+ (if ((r2 & #xC0) != #x80) (end))
+ (if (r1 < #xE0) ((r0 = 1) (repeat)))
+ (read r2)
+ (if ((r2 & #xC0) != #x80) (end))
+ (if (r1 < #xF0) ((r0 = 1) (repeat)))
+ (read r2)
+ (if ((r2 & #xC0) != #x80) (end))
+ (if (r1 < #xF8) ((r0 = 1) (repeat)))
+ (read r2)
+ (if ((r2 & #xC0) != #x80) (end))
+ (if (r1 == #xF8) ((r0 = 1) (repeat)))
+ (end))))))
+ "Check if the input unibyte string is a valid UTF-8 sequence or not.
+If it is valid, set the register `r0' to 1, else set it to 0.")
+
+(defun string-utf-8-p (string)
+ "Return non-nil iff STRING is a unibyte string of valid UTF-8 sequence."
+ (if (or (not (stringp string))
+ (multibyte-string-p string))
+ (error "Not a unibyte string: %s" string))
+ (let ((status (make-vector 9 0)))
+ (ccl-execute-on-string ccl-check-utf-8 status string)
+ (= (aref status 0) 1)))
+
+
(defun xselect-convert-to-string (selection type value)
(let (str coding)
;; Get the actual string from VALUE.
@@ -223,11 +258,10 @@ Cut buffers are considered obsolete; you should use selections instead."
(setq str (encode-coding-string str coding))))
((eq type 'UTF8_STRING)
- (let ((charsets (find-charset-string str)))
- (if (or (memq 'eight-bit-control charsets)
- (memq 'eight-bit-graphic charsets))
- (setq type 'STRING)
- (setq str (encode-coding-string str 'utf-8)))))
+ (if (multibyte-string-p str)
+ (setq str (encode-coding-string str 'utf-8)))
+ (if (not (string-utf-8-p str))
+ (setq str nil))) ;; Decline request as we don't have UTF-8 data.
(t
(error "Unknow selection type: %S" type))
)))