[uim-commit] r797 - in branches/composer: test uim

yamaken at freedesktop.org yamaken at freedesktop.org
Sat Mar 19 04:59:10 PST 2005


Author: yamaken
Date: 2005-03-19 04:59:07 -0800 (Sat, 19 Mar 2005)
New Revision: 797

Modified:
   branches/composer/test/test-uim-util.scm
   branches/composer/uim/uim-util.c
Log:
* uim/uim-util.c
  - (string_prefixp_internal, string_prefixp, string_prefix_cip): New
    function
  - (uim_init_util_subrs): Add initialization of string-prefix? and
    string-prefix-ci?
* test/test-uim-util.scm
  - (test string-prefix?, test string-prefix-ci?): New test


Modified: branches/composer/test/test-uim-util.scm
===================================================================
--- branches/composer/test/test-uim-util.scm	2005-03-19 08:21:53 UTC (rev 796)
+++ branches/composer/test/test-uim-util.scm	2005-03-19 12:59:07 UTC (rev 797)
@@ -124,6 +124,52 @@
 ;		 (uim '(string-to-list "a日b本語c")))
    )
 
+  ("test string-prefix?"
+   (assert-true  (uim-bool '(string-prefix? ""         "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "f"        "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "fo"       "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "foo"      "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "foo_"     "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "foo_b"    "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "foo_ba"   "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix? "foo_bar"  "foo_bar")))
+   (assert-false (uim-bool '(string-prefix? "foo_bar_" "foo_bar")))
+   (assert-false (uim-bool '(string-prefix? #f         "foo_bar")))
+   (assert-false (uim-bool '(string-prefix? "foo_bar"  #f)))
+   (assert-false (uim-bool '(string-prefix? "Foo"      "foo_bar")))
+   (assert-false (uim-bool '(string-prefix? "oo_"      "foo_bar")))
+   (assert-false (uim-bool '(string-prefix? "bar"      "foo_bar")))
+
+   (assert-true  (uim-bool '(string-prefix? ""    "")))
+   (assert-false (uim-bool '(string-prefix? "foo" "")))
+   (assert-false (uim-bool '(string-prefix? #f    "")))
+   (assert-false (uim-bool '(string-prefix? ""    #f))))
+
+  ("test string-prefix-ci?"
+   (assert-true  (uim-bool '(string-prefix-ci? ""         "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "f"        "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "fo"       "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "foo"      "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "foo_"     "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "foo_b"    "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "foo_ba"   "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "foo_bar"  "foo_bar")))
+   (assert-false (uim-bool '(string-prefix-ci? "foo_bar_" "foo_bar")))
+   (assert-false (uim-bool '(string-prefix-ci? #f         "foo_bar")))
+   (assert-false (uim-bool '(string-prefix-ci? "foo_bar"  #f)))
+   (assert-true  (uim-bool '(string-prefix-ci? "Foo"      "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "fOo"      "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "fOO"      "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "FOO"      "foo_bar")))
+   (assert-true  (uim-bool '(string-prefix-ci? "FOO_bar"  "foo_bar")))
+   (assert-false (uim-bool '(string-prefix-ci? "oo_"      "foo_bar")))
+   (assert-false (uim-bool '(string-prefix-ci? "bar"      "foo_bar")))
+
+   (assert-true  (uim-bool '(string-prefix-ci? ""    "")))
+   (assert-false (uim-bool '(string-prefix-ci? "foo" "")))
+   (assert-false (uim-bool '(string-prefix-ci? #f    "")))
+   (assert-false (uim-bool '(string-prefix-ci? ""    #f))))
+
   ("test string=?"
    (assert-true  (uim-bool '(string=? "foo1" "foo1")))
    (assert-true  (uim-bool '(string=? "Foo1" "Foo1")))

Modified: branches/composer/uim/uim-util.c
===================================================================
--- branches/composer/uim/uim-util.c	2005-03-19 08:21:53 UTC (rev 796)
+++ branches/composer/uim/uim-util.c	2005-03-19 12:59:07 UTC (rev 797)
@@ -436,6 +436,35 @@
   return res;
 }
 
+static uim_lisp
+string_prefixp_internal(uim_lisp prefix_, uim_lisp str_,
+			int cmp(const char *, const char *, size_t))
+{
+  const char *prefix, *str;
+  size_t len;
+
+  if (!uim_scm_stringp(prefix_) || !uim_scm_stringp(str_))
+    return uim_scm_f();
+
+  prefix = uim_scm_refer_c_str(prefix_);
+  str = uim_scm_refer_c_str(str_);
+  len = strlen(prefix);
+
+  return cmp(prefix, str, len) ? uim_scm_f() : uim_scm_t();
+}
+
+static uim_lisp
+string_prefixp(uim_lisp prefix_, uim_lisp str_)
+{
+  return string_prefixp_internal(prefix_, str_, strncmp);
+}
+
+static uim_lisp
+string_prefix_cip(uim_lisp prefix_, uim_lisp str_)
+{
+  return string_prefixp_internal(prefix_, str_, strncasecmp);
+}
+
 /* Following is utility functions for C world */
 struct _locale_language_table {
   char *locale;
@@ -520,6 +549,8 @@
   uim_scm_init_subr_1("unsetenv", c_unsetenv);
   uim_scm_init_subr_2("string-split", uim_split_string);
   uim_scm_init_subr_1("string-to-list", eucjp_string_to_list);
+  uim_scm_init_subr_2("string-prefix?", string_prefixp);
+  uim_scm_init_subr_2("string-prefix-ci?", string_prefix_cip);
   uim_scm_init_subr_1("lang-code->lang-name-raw", lang_code_to_lang_name_raw);
   uim_scm_init_subr_0("is-set-ugid?", is_setugidp);
 }



More information about the Uim-commit mailing list