comparison lisp/mule/mule-charset.el @ 3681:3131094eed8c

[xemacs-hg @ 2006-11-15 21:39:51 by aidan] Move charsets-in-region to C.
author aidan
date Wed, 15 Nov 2006 21:40:02 +0000
parents 98af8a976fc3
children a0d288cfcfb5
comparison
equal deleted inserted replaced
3680:efca49973324 3681:3131094eed8c
36 36
37 ;;; Code: 37 ;;; Code:
38 38
39 ;;;; Classifying text according to charsets 39 ;;;; Classifying text according to charsets
40 40
41 ;; the old version was broken in a couple of ways
42 ;; this is one of several versions, I tried a hash as well as the
43 ;; `prev-charset' cache used in the old version, but this was definitely
44 ;; faster than the hash version and marginally faster than the prev-charset
45 ;; version
46 ;; #### this really needs to be moved into C
47 (defun charsets-in-region (start end &optional buffer)
48 "Return a list of the charsets in the region between START and END.
49 BUFFER defaults to the current buffer if omitted."
50 (let (list)
51 (save-excursion
52 (if buffer
53 (set-buffer buffer))
54 (save-restriction
55 (narrow-to-region start end)
56 (goto-char (point-min))
57 (while (not (eobp))
58 ;; the first test will usually succeed on testing the
59 ;; car of the list; don't waste time let-binding.
60 (or (memq (char-charset (char-after (point))) list)
61 (setq list (cons (char-charset (char-after (point))) list)))
62 (forward-char))))
63 list))
64
65 (defun charsets-in-string (string) 41 (defun charsets-in-string (string)
66 "Return a list of the charsets in STRING." 42 "Return a list of the charsets in STRING."
67 (let (list) 43 (let (res)
68 (mapc (lambda (ch) 44 (with-string-as-buffer-contents string
69 ;; the first test will usually succeed on testing the 45 ;; charsets-in-region now in C.
70 ;; car of the list; don't waste time let-binding. 46 (setq res (charsets-in-region (point-min) (point-max))))
71 (or (memq (char-charset ch) list) 47 res))
72 (setq list (cons (char-charset ch) list))))
73 string)
74 list))
75 48
76 (defalias 'find-charset-string 'charsets-in-string) 49 (defalias 'find-charset-string 'charsets-in-string)
50
77 (defalias 'find-charset-region 'charsets-in-region) 51 (defalias 'find-charset-region 'charsets-in-region)
78 52
79 53
80 ;;;; Charset accessors 54 ;;;; Charset accessors
81 55