forked from GitHub/comp-syntax-gu-mlt
57 lines
1.6 KiB
EmacsLisp
57 lines
1.6 KiB
EmacsLisp
(defun hangul-syllables-to-jamo (str)
|
|
"Convert HANGUL SYLLABLES characters in STR to their HANGUL JAMO
|
|
equivalents."
|
|
(let ((result "")
|
|
(i 0))
|
|
(while (< i (length str))
|
|
(let ((char (aref str i)))
|
|
(if (and (>= char #xAC00) (<= char #xD7A3))
|
|
;; Hangul syllable
|
|
(let* ((code (- char #xAC00))
|
|
(lead (/ code (* 21 28)))
|
|
(medial (/ (% code (* 21 28)) 28))
|
|
(final (% code 28))
|
|
(lead-jamo (+ #x1100 lead))
|
|
(medial-jamo (+ #x1161 medial))
|
|
(final-jamo (if (> final 0) (+ #x11A7 final) nil)))
|
|
(setq result
|
|
(concat result (char-to-string lead-jamo)
|
|
(char-to-string medial-jamo)
|
|
(if final-jamo (char-to-string final-jamo) ""))))
|
|
;; Not a Hangul syllable
|
|
(setq result (concat result (char-to-string char)))))
|
|
(setq i (1+ i)))
|
|
result))
|
|
|
|
(defun hangul-convert-region-to-jamo (beg end)
|
|
(interactive "r")
|
|
(replace-region-contents
|
|
beg end (lambda ()
|
|
(hangul-syllables-to-jamo (buffer-substring (point-min)
|
|
(point-max))))))
|
|
|
|
(defun hangul-convert-buffer-to-jamo ()
|
|
(interactive)
|
|
(hangul-convert-region-to-jamo (point-min) (point-max))
|
|
(message "Converted Hangul Syllables in buffer to Jamo."))
|
|
|
|
(require 'dash)
|
|
|
|
(defconst gf-hangul/choseong
|
|
(cl-loop for i from #x1100 to #x1112 collect i))
|
|
|
|
(defconst gf-hangul/jungseong
|
|
(cl-loop for i from #x1161 to #x1175 collect i))
|
|
|
|
(defconst gf-hangul/batchim
|
|
(cl-loop for i from #x11a8 to #x11c2 collect i))
|
|
|
|
(defun gf-hangul/make-pattern (name seq)
|
|
(format "'%s' : pattern Str = #(%s) ;"
|
|
name (->> seq
|
|
(--map (concat "\"" it "\""))
|
|
(-interpose " | ")
|
|
(apply #'concat))))
|
|
|
|
(provide 'helpers)
|