Revision: 6332
Author: ek.kato
Date: Thu Apr 22 07:51:15 2010
Log: * uim/rk.c
  - (rk_expect_key_for_seq) : New.
  - (uim_init_rk_subrs) : Export rk_expect_key_for_seq as
    rk-lib-expect-key-for-seq.
* scm/rk.scm (rk-expect-key) : New.  Added for better response with
  tutucode.scm.
* scm/tutcode.scm : Use rk-expect-key instead of rk-expect for the
  efficiency.
* scm/anthy-utf8.scm : Ditto.
* scm/wnn.scm : Ditto.
* scm/social-ime.scm : Ditto.
* scm/latin.scm : Ditto.
* scm/canna.scm : Ditto.
* scm/ajax-ime.scm : Ditto.
* scm/anthy.scm : Ditto.
* scm/yahoo-jp.scm : Ditto.
* scm/skk.scm : Ditto.
* scm/mana.scm : Ditto.
* scm/sj3.scm : Ditto.

http://code.google.com/p/uim/source/detail?r=6332

Modified:
 /trunk/scm/ajax-ime.scm
 /trunk/scm/anthy-utf8.scm
 /trunk/scm/anthy.scm
 /trunk/scm/canna.scm
 /trunk/scm/latin.scm
 /trunk/scm/mana.scm
 /trunk/scm/rk.scm
 /trunk/scm/sj3.scm
 /trunk/scm/skk.scm
 /trunk/scm/social-ime.scm
 /trunk/scm/tutcode.scm
 /trunk/scm/wnn.scm
 /trunk/scm/yahoo-jp.scm
 /trunk/uim/rk.c

=======================================
--- /trunk/scm/ajax-ime.scm     Mon Apr 19 21:59:12 2010
+++ /trunk/scm/ajax-ime.scm     Thu Apr 22 07:51:15 2010
@@ -1249,8 +1249,7 @@
       ;; handle "n1" sequence as "¤ó1"
       (if (and (not (ajax-ime-context-alnum ac))
               (not (ichar-alphabetic? key))
-              (not (string-find
-                    (rk-expect rkc)
+              (not (rk-expect-key rkc
                     (charcode->string
                      (if (= rule ajax-ime-input-rule-kana)
                          key
=======================================
--- /trunk/scm/anthy-utf8.scm   Sun Apr  4 20:35:54 2010
+++ /trunk/scm/anthy-utf8.scm   Thu Apr 22 07:51:15 2010
@@ -1237,8 +1237,7 @@
        ;; handle "n1" sequence as "ん1"
        (if (and (not (anthy-utf8-context-alnum ac))
                 (not (ichar-alphabetic? key))
-                (not (string-find
-                      (rk-expect rkc)
+                (not (rk-expect-key rkc
                       (if (= rule anthy-input-rule-kana)
                           (if (symbol? key)
                               (symbol->string key)
=======================================
--- /trunk/scm/anthy.scm        Sun Apr  4 20:35:54 2010
+++ /trunk/scm/anthy.scm        Thu Apr 22 07:51:15 2010
@@ -1232,8 +1232,7 @@
        ;; handle "n1" sequence as "¤ó1"
        (if (and (not (anthy-context-alnum ac))
                 (not (ichar-alphabetic? key))
-                (not (string-find
-                      (rk-expect rkc)
+                (not (rk-expect-key rkc
                       (if (= rule anthy-input-rule-kana)
                           (if (symbol? key)
                               (symbol->string key)
=======================================
--- /trunk/scm/canna.scm        Tue Apr 13 00:03:37 2010
+++ /trunk/scm/canna.scm        Thu Apr 22 07:51:15 2010
@@ -1115,8 +1115,7 @@
       ;; handle "n1" sequence as "¤ó1"
       (if (and (not (canna-context-alnum cc))
               (not (ichar-alphabetic? key))
-              (not (string-find
-                    (rk-expect rkc)
+              (not (rk-expect-key rkc
                     (charcode->string
                      (if (= rule canna-input-rule-kana)
                          key
=======================================
--- /trunk/scm/latin.scm        Sun Apr  4 20:35:54 2010
+++ /trunk/scm/latin.scm        Thu Apr 22 07:51:15 2010
@@ -1653,7 +1653,7 @@
                      (eq? 'Multi_key key))))
            (and
             (eqv? 32 key) ; space
-            (not (string-find (rk-expect rkc) " "))))
+            (not (rk-expect-key rkc " "))))
        (latin-commit lc)
        (im-commit-raw lc)
        (latin-context-flush lc))
=======================================
--- /trunk/scm/mana.scm Sun Apr  4 20:35:54 2010
+++ /trunk/scm/mana.scm Thu Apr 22 07:51:15 2010
@@ -1175,8 +1175,7 @@
        ;; handle "n1" sequence as "¤ó1"
        (if (and (not (mana-context-alnum mc))
                 (not (ichar-alphabetic? key))
-                (not (string-find
-                      (rk-expect rkc)
+                (not (rk-expect-key rkc
                       (charcode->string
                        (if (= rule mana-input-rule-kana)
                            key
=======================================
--- /trunk/scm/rk.scm   Sun Apr  4 20:35:54 2010
+++ /trunk/scm/rk.scm   Thu Apr 22 07:51:15 2010
@@ -248,6 +248,8 @@
          (rk-context-set-seq! context s)
          #f))))
 ;; API
+;; return list of all expected next characters for the current partial sequence
+;; return '() if current rkc is not partial
 (define rk-expect
   (lambda (rkc)
     (let
@@ -255,6 +257,17 @@
         (rule (rk-context-rule rkc)))
       (rk-lib-expect-seq s rule))))

+;; API
+;; return #t if the key is expected as a next character in the partial sequence
+;; this should be faster than rk-expect
+(define rk-expect-key
+  (lambda (rkc key)
+    (let
+       ((s (reverse (rk-context-seq rkc)))
+        (rule (rk-context-rule rkc)))
+      (rk-lib-expect-key-for-seq s rule key))))
+
+
 ;; back match
 (define rk-push-key-back-match
   (lambda (rkc key)
=======================================
--- /trunk/scm/sj3.scm  Sun Apr 11 06:48:34 2010
+++ /trunk/scm/sj3.scm  Thu Apr 22 07:51:15 2010
@@ -1396,8 +1396,7 @@
       ;; handle "n1" sequence as "¤ó1"
       (if (and (not (sj3-context-alnum sc))
               (not (ichar-alphabetic? key))
-              (not (string-find
-                    (rk-expect rkc)
+              (not (rk-expect-key rkc
                     (charcode->string
                      (if (= rule sj3-input-rule-kana)
                          key
=======================================
--- /trunk/scm/skk.scm  Sun Apr  4 20:35:54 2010
+++ /trunk/scm/skk.scm  Thu Apr 22 07:51:15 2010
@@ -1031,21 +1031,21 @@
        ;; 1. commits "n" as kana according to kana-mode
        ;; 2. switch mode by "{L,l,/,Q,C-q,C-Q,q}"
        (if (and (skk-wide-latin-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (begin
             (set! res (rk-push-key-last! rkc))
             (skk-context-set-state! sc 'skk-state-wide-latin)
             #f)
           #t)
        (if (and (skk-latin-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (begin
             (set! res (rk-push-key-last! rkc))
             (skk-context-set-state! sc 'skk-state-latin)
             #f)
           #t)
        (if (and (skk-latin-conv-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (let* ((residual-kana (rk-push-key-last! rkc)))
             (if residual-kana
                 (skk-commit sc (skk-get-string sc residual-kana kana)))
@@ -1054,7 +1054,7 @@
             #f)
           #t)
        (if (and (skk-kanji-mode-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (let* ((residual-kana (rk-push-key-last! rkc)))
             (if residual-kana
                 (skk-commit sc (skk-get-string sc residual-kana kana)))
@@ -1063,7 +1063,7 @@
             #f)
           #t)
        (if (and (skk-hankaku-kana-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (let* ((kana (skk-context-kana-mode sc))
                  (new-kana (if (= kana skk-type-hankana)
                                  skk-type-hiragana
@@ -1073,7 +1073,7 @@
             #f)
           #t)
        (if (and (skk-kana-toggle-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (begin
             (set! res (rk-push-key-last! rkc))
             (skk-context-kana-toggle sc)
@@ -1085,7 +1085,7 @@
        ;; 2. commits " " as native space (such as Qt::Key_Space)
        ;;    unless expected rkc list includes " "
        (if (and (skk-plain-space-key? key key-state)
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (begin
             (set! res (rk-push-key-last! rkc))
             (skk-commit-raw-with-preedit-update sc key key-state)
@@ -1129,7 +1129,7 @@
        ;; Hack to handle "n1" sequence as "¤ó1".
        ;; This should be handled in rk.scm. -- ekato
        (if (and (not (ichar-alphabetic? key))
-               (not (string-find (rk-expect rkc) key-str)))
+               (not (rk-expect-key rkc key-str)))
           (let* ((residual-kana (rk-push-key-last! rkc)))
             (if residual-kana
                 (skk-commit sc (skk-get-string sc residual-kana kana)))
@@ -1483,8 +1483,7 @@
        ;; Hack to handle "n1" sequence as "¤ó1".
        ;; This should be handled in rk.scm. -- ekato
        (if (and (not (ichar-alphabetic? key))
-               (not (string-find
-                     (rk-expect rkc)
+               (not (rk-expect-key rkc
                      (charcode->string (ichar-downcase key)))))
           (let* ((residual-kana (rk-push-key-last! rkc)))
             (if residual-kana
=======================================
--- /trunk/scm/social-ime.scm   Tue Apr 13 00:03:37 2010
+++ /trunk/scm/social-ime.scm   Thu Apr 22 07:51:15 2010
@@ -1311,8 +1311,7 @@
       ;; handle "n1" sequence as "¤ó1"
       (if (and (not (social-ime-context-alnum sc))
               (not (ichar-alphabetic? key))
-              (not (string-find
-                    (rk-expect rkc)
+              (not (rk-expect-key rkc
                     (charcode->string
                      (if (= rule social-ime-input-rule-kana)
                          key
=======================================
--- /trunk/scm/tutcode.scm      Fri Apr  9 06:16:55 2010
+++ /trunk/scm/tutcode.scm      Thu Apr 22 07:51:15 2010
@@ -566,7 +566,7 @@
       ;; Àµ¤·¤¯¤Ê¤¤¥­¡¼¥·¡¼¥±¥ó¥¹¤ÏÁ´¤Æ¼Î¤Æ¤ë(tc2¤Ë¹ç¤ï¤»¤¿Æ°ºî)¡£
       ;; (rk-push-key!¤¹¤ë¤È¡¢ÅÓÃæ¤Þ¤Ç¤Î¥·¡¼¥±¥ó¥¹¤Ï¼Î¤Æ¤é¤ì¤ë¤¬¡¢
       ;; ´Ö°ã¤Ã¤¿¥­¡¼¤Ï»Ä¤Ã¤Æ¤·¤Þ¤¦¤Î¤Ç¡¢rk-push-key!¤Ï»È¤¨¤Ê¤¤)
-      ((not (member (charcode->string key) (rk-expect rkc)))
+      ((not (rk-expect-key rkc (charcode->string key)))
        (if (> (length (rk-context-seq rkc)) 0)
          (rk-flush rkc) ; Àµ¤·¤¯¤Ê¤¤¥·¡¼¥±¥ó¥¹¤Ï¼Î¤Æ¤ë
          (im-commit-raw pc))) ; ñÆÈ¤Î¥­¡¼ÆþÎÏ(TUT-CodeÆþÎϤǤʤ¯¤Æ)
@@ -683,7 +683,7 @@
          (begin
            (tutcode-flush pc)
            (tutcode-proc-state-on pc key key-state))))
-      ((not (member (charcode->string key) (rk-expect rkc)))
+      ((not (rk-expect-key rkc (charcode->string key)))
        (if (> (length (rk-context-seq rkc)) 0)
          (rk-flush rkc)
          ;; space¥­¡¼¤Ç¤ÎÊÑ´¹³«»Ï?
@@ -756,7 +756,7 @@
           (not (shift-key-mask key-state))))
        (tutcode-flush pc)
        (tutcode-proc-state-on pc key key-state))
-      ((not (member (charcode->string key) (rk-expect rkc)))
+      ((not (rk-expect-key rkc (charcode->string key)))
        (if (> (length (rk-context-seq rkc)) 0)
          (rk-flush rkc)
          (set! res (charcode->string key))))
=======================================
--- /trunk/scm/wnn.scm  Tue Apr 13 00:03:37 2010
+++ /trunk/scm/wnn.scm  Thu Apr 22 07:51:15 2010
@@ -1169,8 +1169,7 @@
       ;; handle "n1" sequence as "¤ó1"
       (if (and (not (wnn-context-alnum wc))
               (not (ichar-alphabetic? key))
-              (not (string-find
-                    (rk-expect rkc)
+              (not (rk-expect-key rkc
                     (charcode->string
                      (if (= rule wnn-input-rule-kana)
                          key
=======================================
--- /trunk/scm/yahoo-jp.scm     Tue Apr 13 00:03:37 2010
+++ /trunk/scm/yahoo-jp.scm     Thu Apr 22 07:51:15 2010
@@ -1327,8 +1327,7 @@
       ;; handle "n1" sequence as "¤ó1"
       (if (and (not (yahoo-jp-context-alnum yc))
               (not (ichar-alphabetic? key))
-              (not (string-find
-                    (rk-expect rkc)
+              (not (rk-expect-key rkc
                     (charcode->string
                      (if (= rule yahoo-jp-input-rule-kana)
                          key
=======================================
--- /trunk/uim/rk.c     Sun Apr  4 20:35:54 2010
+++ /trunk/uim/rk.c     Thu Apr 22 07:51:15 2010
@@ -140,6 +140,27 @@
   }
   return res;  /* don't return uim_scm_f() */
 }
+
+/*
+ * returns #t if key is expected
+ * (rk-lib-expect-seq-for-key '("k" "y") ja-rk-rule "o") -> #t
+ * (rk-lib-expect-seq-for-key '("k" "y") ja-rk-rule "y") -> #f
+ */
+static uim_lisp
+rk_expect_key_for_seq(uim_lisp seq, uim_lisp rules, uim_lisp key)
+{
+  uim_lisp cur;
+  for (cur = rules; !uim_scm_nullp(cur); cur = uim_scm_cdr(cur)) {
+    uim_lisp rule = uim_scm_car(cur);
+    uim_lisp seq_in_rule = CAR(CAR(rule));
+    uim_lisp e = str_seq_partial(seq, seq_in_rule);
+    if (TRUEP(e) && string_equalp(e, key)) {
+      return uim_scm_t();
+    }
+  }
+  return uim_scm_f();
+}
+

 void
 uim_init_rk_subrs(void)
@@ -149,4 +170,5 @@
   uim_scm_init_proc2("rk-lib-find-seq", rk_find_seq);
   uim_scm_init_proc2("rk-lib-find-partial-seq", rk_find_partial_seq);
   uim_scm_init_proc2("rk-lib-expect-seq", rk_expect_seq);
-}
+  uim_scm_init_proc3("rk-lib-expect-key-for-seq", rk_expect_key_for_seq);
+}


--
Subscription settings: http://groups.google.com/group/uim-commit/subscribe?hl=en

Reply via email to