Function: ctext-post-read-conversion

ctext-post-read-conversion is a byte-compiled function defined in mule.el.gz.

Signature

(ctext-post-read-conversion LEN)

Documentation

Decode LEN characters encoded as Compound Text with Extended Segments.

Source Code

;; Defined in /usr/src/emacs/lisp/international/mule.el.gz
;; Functions to support "Non-Standard Character Set Encodings" defined
;; by the COMPOUND-TEXT spec.  They also support "The UTF-8 encoding"
;; described in the section 7 of the documentation of COMPOUND-TEXT
;; distributed with XFree86.

(defun ctext-post-read-conversion (len)
  "Decode LEN characters encoded as Compound Text with Extended Segments."
  ;; We don't need the following because it is expected that this
  ;; function is mainly used for decoding X selection which is not
  ;; that big data.
  ;;(buffer-disable-undo) ; minimize consing due to insertions and deletions
  (save-match-data
    (save-restriction
      (narrow-to-region (point) (+ (point) len))
      (let ((case-fold-search nil)
	    last-coding-system-used
	    pos bytes)
	(decode-coding-region (point-min) (point-max) 'ctext)
	(while (re-search-forward ctext-non-standard-encodings-regexp
				  nil 'move)
	  (setq pos (match-beginning 0))
	  (if (match-beginning 1)
	      ;; ESC % / [0-4] M L --ENCODING-NAME-- \002 --BYTES--
	      (let* ((M (multibyte-char-to-unibyte (char-after (+ pos 4))))
		     (L (multibyte-char-to-unibyte (char-after (+ pos 5))))
		     (encoding (match-string 2))
		     (encoding-info (assoc-string
				     encoding
				     ctext-non-standard-encodings-alist t))
		     (coding (if encoding-info
				 (nth 1 encoding-info)
			       (setq encoding (intern (downcase encoding)))
			       (and (coding-system-p encoding)
				    encoding))))
		(setq bytes (- (+ (* (- M 128) 128) (- L 128))
			       (- (point) (+ pos 6))))
		(when coding
		  (delete-region pos (point))
		  (forward-char bytes)
		  (decode-coding-region (- (point) bytes) (point) coding)))
	    ;; ESC % G --UTF-8-BYTES-- ESC % @
	    (delete-char -3)
	    (delete-region pos (+ pos 3))
	    (decode-coding-region pos (point) 'utf-8))))
      (goto-char (point-min))
      (- (point-max) (point)))))