*** empty log message ***
[m17n/m17n-lib.git] / src / mtext.c
index 22d6cee..a5a3ecd 100644 (file)
@@ -1,5 +1,5 @@
 /* mtext.c -- M-text module.
-   Copyright (C) 2003, 2004
+   Copyright (C) 2003, 2004, 2005
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
@@ -93,6 +93,9 @@
 #include "character.h"
 #include "mtext.h"
 #include "plist.h"
+#ifdef HAVE_THAI_WORDSEG
+#include "word-thai.h"
+#endif
 
 static M17NObjectArray mtext_table;
 
@@ -682,11 +685,17 @@ case_compare (MText *mt1, int from1, int to1, MText *mt2, int from2, int to2)
 \f
 /* Internal API */
 
+MCharTable *wordseg_func_table;
+
 int
 mtext__init ()
 {
   M_charbag = msymbol_as_managing_key ("  charbag");
   mtext_table.count = 0;
+  wordseg_func_table = mchartable (Mnil, NULL);
+#ifdef HAVE_THAI_WORDSEG
+  mtext__word_thai_init ();
+#endif
   return 0;
 }
 
@@ -694,6 +703,11 @@ mtext__init ()
 void
 mtext__fini (void)
 {
+#ifdef HAVE_THAI_WORDSEG
+  mtext__word_thai_fini ();
+#endif
+  M17N_OBJECT_UNREF (wordseg_func_table);
+  wordseg_func_table = NULL;
   mdebug__report_object ("M-text", &mtext_table);
 }
 
@@ -1103,6 +1117,22 @@ mtext__eol (MText *mt, int pos)
     }
 }
 
+typedef int (*MTextWordsegFunc) (MText *mt, int pos, int *from, int *to);
+
+int
+mtext__word_segment (MText *mt, int pos, int *from, int *to)
+{
+  int c = mtext_ref_char (mt, pos);
+  MTextWordsegFunc func
+    = (MTextWordsegFunc) mchartable_lookup (wordseg_func_table, c);
+
+  if (func)
+    return (func) (mt, pos, from, to);
+  *from = *to = pos;
+  return -1;
+}
+
+
 /*** @} */
 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */