aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/select.el
diff options
context:
space:
mode:
authorKaroly Lorentey2006-12-03 12:25:18 +0000
committerKaroly Lorentey2006-12-03 12:25:18 +0000
commitd6e01aa592f7326dffeafa6e97180a1cc39fe7ea (patch)
tree5a22b785cfee1d77d6452607450a12ca82eeecd3 /lisp/select.el
parent14bcc1e098410087a837313e2fc822319ff2e8ca (diff)
parent4975e69596a64247e8995d1ff9084b98a9a5ed0d (diff)
downloademacs-d6e01aa592f7326dffeafa6e97180a1cc39fe7ea.tar.gz
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."
152;;; Every selection type that Emacs handles is implemented this way, except 152;;; Every selection type that Emacs handles is implemented this way, except
153;;; for TIMESTAMP, which is a special case. 153;;; for TIMESTAMP, which is a special case.
154 154
155(eval-when-compile (require 'ccl))
156
157(define-ccl-program ccl-check-utf-8
158 '(0
159 ((r0 = 1)
160 (loop
161 (read-if (r1 < #x80) (repeat)
162 ((r0 = 0)
163 (if (r1 < #xC2) (end))
164 (read r2)
165 (if ((r2 & #xC0) != #x80) (end))
166 (if (r1 < #xE0) ((r0 = 1) (repeat)))
167 (read r2)
168 (if ((r2 & #xC0) != #x80) (end))
169 (if (r1 < #xF0) ((r0 = 1) (repeat)))
170 (read r2)
171 (if ((r2 & #xC0) != #x80) (end))
172 (if (r1 < #xF8) ((r0 = 1) (repeat)))
173 (read r2)
174 (if ((r2 & #xC0) != #x80) (end))
175 (if (r1 == #xF8) ((r0 = 1) (repeat)))
176 (end))))))
177 "Check if the input unibyte string is a valid UTF-8 sequence or not.
178If it is valid, set the register `r0' to 1, else set it to 0.")
179
180(defun string-utf-8-p (string)
181 "Return non-nil iff STRING is a unibyte string of valid UTF-8 sequence."
182 (if (or (not (stringp string))
183 (multibyte-string-p string))
184 (error "Not a unibyte string: %s" string))
185 (let ((status (make-vector 9 0)))
186 (ccl-execute-on-string ccl-check-utf-8 status string)
187 (= (aref status 0) 1)))
188
189
155(defun xselect-convert-to-string (selection type value) 190(defun xselect-convert-to-string (selection type value)
156 (let (str coding) 191 (let (str coding)
157 ;; Get the actual string from VALUE. 192 ;; Get the actual string from VALUE.
@@ -223,11 +258,10 @@ Cut buffers are considered obsolete; you should use selections instead."
223 (setq str (encode-coding-string str coding)))) 258 (setq str (encode-coding-string str coding))))
224 259
225 ((eq type 'UTF8_STRING) 260 ((eq type 'UTF8_STRING)
226 (let ((charsets (find-charset-string str))) 261 (if (multibyte-string-p str)
227 (if (or (memq 'eight-bit-control charsets) 262 (setq str (encode-coding-string str 'utf-8)))
228 (memq 'eight-bit-graphic charsets)) 263 (if (not (string-utf-8-p str))
229 (setq type 'STRING) 264 (setq str nil))) ;; Decline request as we don't have UTF-8 data.
230 (setq str (encode-coding-string str 'utf-8)))))
231 (t 265 (t
232 (error "Unknow selection type: %S" type)) 266 (error "Unknow selection type: %S" type))
233 ))) 267 )))