;;; Steps toward composition of Devanagari Characters.
;;;
-;;; Intersection Function will be used.
-(require 'cl)
-
;;;###autoload
(defun setup-devanagari-environment ()
"Setup multilingual environment (MULE) for languages using Devanagari."
;;;###autoload
(defun indian-to-devanagari-string (str)
"Convert Indian String to Devanagari Basic Character String."
- (let ((pos 0) (dst "") (src str) char)
- (while (not (equal src ""))
- (setq char (string-to-char src))
- (setq src (substring src (char-bytes char)))
- (setq dst (concat dst (char-to-string (indian-to-devanagari char)))))
- dst))
+ (let* ((len (length str))
+ (i 0)
+ (vec (make-vector len 0)))
+ (while (< i len)
+ (aset vec i (indian-to-devanagari (aref str i)))
+ (setq i (1+ i)))
+ (concat vec)))
;; Phase 0 - Determine whether the characters can be composed.
;;
;;
;; Compose the glyph.
;;
-;; => \e2\e$(6!X@![\e1\e(B/\e2\e$(6!D@"FP!\\e1\e(B
-;; => \e2\e$(6!X@![\e1\e2!D@"FP!\\e1\e(B
+;; => \e2\e$(6!X@![\e(B\e1/\e2\e$(6!D@"FP!\\e(B\e1
+;; => \e2\e$(6!X@![\e(B\e1\e2\e$(6!D@"FP!\\e(B\e1
;;
;;
;;
(defun max-match-len (regexp-str)
- "This returns the possible length of matched string of given regexp.
- Only [...] pattern of regexp is recognized. The last character of
- inside of [....] is used for its length."
+ "Return the possible length of matched string of given regexp.
+Only [...] pattern of regexp is recognized.
+The last character of inside of [....] is used for its length."
(let ((dest-str regexp-str))
(while (string-match "\\[\\([^\]]\\)+\\]" dest-str)
(setq dest-str
(substring dest-str (match-end 0)))))
(length dest-str)))
+;; Return t iff LIST1 and LIST2 has a same member.
+(defun rule-intersection (list1 list2)
+ (let ((found nil))
+ (while (and list1 (not found))
+ (if (memq (car list1) list2)
+ (setq found t)
+ (setq list1 (cdr list1))))
+ found))
+
(defun string-conversion-by-rule (src-str symbol &rest specs)
- " This function converts the SRC-STR to the new string according to
+ "Convert string SRC-STR to a new string according to
the rules described in the each character's SYMBOL property. The
rules are described in the forms of '((regexp str <specs>) ...), and
the character sequence in the string which matches to 'regexp' are
(rule-specs (cdr (cdr rule)))
search-pos)
(if (not (or (null rule-specs)
- (intersection specs rule-specs)))
+ (rule-intersection specs rule-specs)))
(setq rules (cdr rules))
(if (null (string-match "\\\\(.+\\\\)" regexp))
(progn
(setq rules (cdr rules))))))
;; proceed to next position
(if (not found)
- (let ((nextchar (string-to-char (substring src-str pos))))
- (setq pos (+ pos
- (char-bytes (string-to-char (substring src-str pos)))))
- (setq dst-str (concat dst-str (char-to-string nextchar)))))))
+ (setq dst-str (concat dst-str (substring src-str pos (1+ pos)))
+ pos (1+ pos)))))
dst-str))
(append ordered-glyphs (list (assq glyph devanagari-composition-rules))))))
(sort ordered-glyphs '(lambda (x y) (< (car (cdr x)) (car (cdr y)))))))
-;;(devanagari-compose-to-one-glyph "\e$(5"5!X![\e(B") => "\e2\e$(6!XP"5@![\e1\e(B"
+;;(devanagari-compose-to-one-glyph "\e$(5"5!X![\e(B") => "\e2\e$(6!XP"5@![\e(B\e1"
(defun devanagari-compose-to-one-glyph (devanagari-string)
(let* ((o-glyph-list (devanagari-reorder-glyphs-for-composition
;;;###autoload
(defun devanagari-decompose-string (str)
- "This function Decomposes Devanagari glyph string to
-basic Devanagari character string."
- (let ((src str) (dst ""))
- (while (not (equal src ""))
- (let* ((char (string-to-char src))
- (clen (char-bytes char)))
- (setq src (substring src clen))
- (setq dst (concat dst
- (devanagari-decompose-char char)))))
+ "Decompose Devanagari glyph string STR to basic Devanagari character string."
+ (let ((len (length str))
+ (i 0)
+ (dst ""))
+ (while (< i len)
+ (setq dst (concat dst (devanagari-decompose-char (aref str i)))
+ i (1+ i)))
dst))
;;;###autoload