(struct MInputContext): Fix typo in comment.
[m17n/m17n-lib.git] / src / character.c
index 4f3642b..45ba1fd 100644 (file)
@@ -1,5 +1,5 @@
 /* character.c -- character module.
-   Copyright (C) 2003, 2004
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H15PRO112
 
@@ -17,7 +17,7 @@
 
    You should have received a copy of the GNU Lesser General Public
    License along with the m17n library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    02111-1307, USA.  */
 
 /***en
@@ -95,22 +95,17 @@ free_string (int from, int to, void *str, void *arg)
 int
 mchar__init ()
 {
-  char_prop_list = mplist ();
-
-  Mname
-    = mchar_define_property ("name", Mstring);
-  Mcategory
-    = mchar_define_property ("category", Msymbol);
-  Mcombining_class
-    = mchar_define_property ("combining-class", Minteger);
-  Mbidi_category
-    = mchar_define_property ("bidirectional-category", Msymbol);
-  Msimple_case_folding
-    = mchar_define_property ("simple-case-folding", Minteger);
-  Mcomplicated_case_folding
-    = mchar_define_property ("complicated-case-folding", Mtext);
-  Mscript
-    = mchar_define_property ("script", Msymbol);
+  Mname = msymbol ("name");
+  Mcategory = msymbol ("category");
+  Mcombining_class = msymbol ("combining-class");
+  Mbidi_category = msymbol ("bidirectional-category");
+  Msimple_case_folding = msymbol ("simple-case-folding");
+  Mcomplicated_case_folding = msymbol ("complicated-case-folding");
+  Mcased = msymbol ("cased");
+  Msoft_dotted = msymbol ("soft-dotted");
+  Mcase_mapping = msymbol ("case-mapping");
+  Mblock = msymbol ("block");
+  Mscript = msymbol ("script");
 
   return 0;
 }
@@ -120,21 +115,61 @@ mchar__fini (void)
 {
   MPlist *p;
 
-  for (p = char_prop_list; mplist_key (p) != Mnil; p = mplist_next (p))
+  if (char_prop_list)
     {
-      MCharPropRecord *record = mplist_value (p);
-
-      if (record->table)
+      for (p = char_prop_list; mplist_key (p) != Mnil; p = mplist_next (p))
        {
-         if (record->type == Mstring)
-           mchartable_map (record->table, NULL, free_string, NULL);
-         M17N_OBJECT_UNREF (record->table);
+         MCharPropRecord *record = mplist_value (p);
+
+         if (record->table)
+           {
+             if (record->type == Mstring)
+               mchartable_map (record->table, NULL, free_string, NULL);
+             M17N_OBJECT_UNREF (record->table);
+           }
+         free (record);
        }
-      free (record);
+      M17N_OBJECT_UNREF (char_prop_list);
     }
-  M17N_OBJECT_UNREF (char_prop_list);
 }
 
+void
+mchar__define_prop (MSymbol key, MSymbol type, void *mdb)
+{
+  MCharPropRecord *record;
+
+  if (char_prop_list)
+    record = mplist_get (char_prop_list, key);
+  else
+    char_prop_list = mplist (), record = NULL;
+  if (record)
+    {
+      if (record->table)
+       M17N_OBJECT_UNREF (record->table);
+    }
+  else
+    {
+      MSTRUCT_CALLOC (record, MERROR_CHAR);
+      mplist_put (char_prop_list, key, record);
+    }
+
+  record->type = type;
+  record->mdb = mdb;
+  if (mdb)
+    {
+      record->table = NULL;
+    }
+  else
+    {
+      void *default_value = NULL;
+
+      if (type == Minteger)
+       default_value = (void *) -1;
+      record->table = mchartable (type, default_value);
+    }
+}
+
+
 /*** @} */
 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
 \f
@@ -169,6 +204,8 @@ mchar__fini (void)
     @name ÊÑ¿ô: Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼
 
     ¤³¤ì¤é¤Î¥·¥ó¥Ü¥ë¤Ïʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£*/
+
+/*=*/
 /*** @{ */
 
 /***en
@@ -315,6 +352,8 @@ MSymbol Mbidi_category;
     ¤È¤¤¤¦¥­¡¼¤Îʸ»ú¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¡£  */
 
 MSymbol Msimple_case_folding;
+/*=*/
+
 /***en
     @brief Key for corresponding multiple lowercase characters.
 
@@ -336,6 +375,86 @@ MSymbol Msimple_case_folding;
 
 MSymbol Mcomplicated_case_folding;
 /*=*/
+
+/***en
+    @brief Key for values used in case operation.
+
+    The symbol #Mcased has the name <tt>"cased"</tt> and is used as
+    the key of charater property.  The value of such a property is an
+    integer value 1, 2, or 3 representing "cased", "case-ignorable",
+    and both of them respective.  See the Unicode Standard 5.0
+    (Section 3.13 Default Case Algorithm) for the detail.
+ */
+
+/***ja
+    @brief Case ½èÍý¤ËÍѤ¤¤é¤ì¤ëÃͤΥ­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcased ¤Ï¡¢<tt>"cased"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢Ê¸»ú¥×¥í¥Ñ
+    ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤÏÀ°¿ôÃÍ 1, 2, 3 ¤Î¤¤¤º
+    ¤ì¤«¤Ç¤¢¤ê¡¢¤½¤ì¤¾¤ì "cased", "case-ignorable", ¤½¤ÎξÊý¤ò°ÕÌ£¤¹¤ë¡£
+    ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢the Unicode Standard 5.0 (Section 3.13 Default
+    Case Algorithm) »²¾È¡£
+ */
+MSymbol Mcased;
+
+/*=*/
+/***en
+    @brief Key for values used in case operation.
+
+    The symbol #Msoft_dotted has the name <tt>"soft-dotted"</tt> and
+    is used as the key of charater property.  The value of such a
+    property is #Mt if a character has "Soft_Dotted" property, and
+    #Mnil otherwise.  See the Unicode Standard 5.0 (Section 3.13
+    Default Case Algorithm) for the detail.  */
+
+/***ja
+    @brief Case ½èÍý¤ËÍѤ¤¤é¤ì¤ëÃͤΥ­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Msoft_dotted ¤Ï¡¢<tt>"soft-dotted"</tt> ¤È¤¤¤¦Ì¾Á°¤ò»ý¤Á¡¢
+    Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢Ê¸»ú¤¬
+    "Soft_Dotted"¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¾ì¹ç¤Ë¤Ï #Mt, ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð #Mnil ¤Ç
+    ¤¢¤ë¡£ ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢the Unicode Standard 5.0 (Section 3.13
+    Default Case Algorithm) »²¾È¡£
+ */
+MSymbol Msoft_dotted;
+
+/*=*/
+/***en 
+    @brief Key for values used in case operation.
+
+    The symbol #Mcase_mapping has the name <tt>"case-mapping"</tt> and
+    is used as the key of charater property.  The value of such a
+    property is a plist of three M-Texts; lower, title, and upper of
+    the corresponding character.  See the Unicode Standard 5.0
+    (Section 5.18 Case Mappings) for the detail.  */
+
+/***ja
+    @brief Case ½èÍý¤ËÍѤ¤¤é¤ì¤ëÃͤΥ­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mcase_mapping ¤Ï¡¢<tt>"case-mapping"</tt> ¤È¤¤¤¦Ì¾Á°¤ò¤â
+    ¤Á¡¢Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢£³¤Ä
+    ¤Î M-text¡¢¤¹¤Ê¤ï¤Á¤½¤Îʸ»ú¤Î lower, title, ¤È upper¤«¤é¤Ê¤ë plist
+    ¤Ç¤¢¤ë¡£ ¾ÜºÙ¤Ë¤Ä¤¤¤Æ¤Ï¡¢the Unicode Standard 5.0 (Section 3.13
+    Default Case Algorithm) »²¾È¡£
+*/
+MSymbol Mcase_mapping;
+
+/*=*/
+/***en 
+    @brief Key for script block name.
+
+    The symbol #Mblock the name <tt>"block"</tt> and is used as the
+    key of charater property.  The value of such a property is a
+    symbol representing a script block of the corresponding
+    character.  */
+/***ja
+    @brief ¥¹¥¯¥ê¥×¥È¥Ö¥í¥Ã¥¯Ì¾¤òɽ¤¹¥­¡¼.
+
+    ¥·¥ó¥Ü¥ë #Mblock ¤Ï¡¢<tt>"block"</tt> ¤È¤¤¤¦Ì¾Á°¤ò¤â¤Á¡¢Ê¸»ú¥×¥í¥Ñ
+    ¥Æ¥£¤Î¥­¡¼¤È¤·¤Æ»È¤ï¤ì¤ë¡£¤³¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤϡ¢¤½¤Îʸ»ú¤Î¥¹¥¯¥ê¥×
+    ¥È¥Ö¥í¥Ã¥¯Ì¾¤òɽ¤¹¥·¥ó¥Ü¥ë¤Ç¤¢¤ë¡£*/
+MSymbol Mblock;
+
 /*** @} */
 /*=*/
 
@@ -374,36 +493,12 @@ MSymbol
 mchar_define_property (const char *name, MSymbol type)
 {
   MSymbol key = msymbol (name);
-  MCharPropRecord *record;
-
-  record = mplist_get (char_prop_list, key);
-  if (record)
-    {
-      if (record->table)
-       M17N_OBJECT_UNREF (record->table);
-    }
-  else
-    {
-      MSTRUCT_CALLOC (record, MERROR_CHAR);
-      mplist_put (char_prop_list, key, record);
-    }
-
-  record->type = type;
-  if (mdatabase__finder
-      && (record->mdb = (*mdatabase__finder) (Mchar_table, type, key, Mnil)))
-    {
-      record->table = NULL;
-    }
-  else
-    {
-      void *default_value = NULL;
-
-      record->mdb = NULL;
-      if (type == Minteger)
-       default_value = (void *) -1;
-      record->table = mchartable (type, default_value);
-    }
+  void *mdb;
 
+  mdb = mdatabase_find (Mchar_table, type, key, Mnil);
+  if (! mdb)
+    return Mnil;
+  mchar__define_prop (key, type, mdb);
   return key;
 }
 
@@ -444,12 +539,14 @@ mchar_get_prop (int c, MSymbol key)
 {
   MCharPropRecord *record;
 
+  if (! char_prop_list)
+    return NULL;
   record = mplist_get (char_prop_list, key);
   if (! record)
     return NULL;
   if (record->mdb)
     {
-      record->table = (*mdatabase__loader) (record->mdb);
+      record->table = mdatabase_load (record->mdb);
       if (! record->table)
        MERROR (MERROR_DB, NULL);
       record->mdb = NULL;
@@ -489,12 +586,14 @@ mchar_put_prop (int c, MSymbol key, void *val)
 {
   MCharPropRecord *record;
 
+  if (! char_prop_list)
+    MERROR (MERROR_CHAR, -1);
   record = mplist_get (char_prop_list, key);
   if (! record)
     return -1;
   if (record->mdb)
     {
-      record->table = (*mdatabase__loader) (record->mdb);
+      record->table = mdatabase_load (record->mdb);
       if (! record->table)
        MERROR (MERROR_DB, -1);
       record->mdb = NULL;
@@ -509,26 +608,39 @@ mchar_put_prop (int c, MSymbol key, void *val)
 
     The mchar_get_prop_table () function returns a char-table that
     contains the character property whose key is $KEY.  If $TYPE is
-    not null, this function store the type of the property in the
+    not NULL, this function stores the type of the property in the
     place pointed by $TYPE.  See mchar_define_property () for types of
     character property.
 
     @return
-    If $KEY is a valid character property key, return a char-table.
-    Otherwise retun NULL.  */
+    If $KEY is a valid character property key, this function returns a
+    char-table.  Otherwise NULL is retuned.  */
+
+/***ja
+    @brief Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Îʸ»ú¥Æ¡¼¥Ö¥ë¤òÆÀ¤ë.
 
+    ´Ø¿ô mchar_get_prop_table () ¤Ï¡¢¥­¡¼¤¬ $KEY ¤Ç¤¢¤ëʸ»ú¥×¥í¥Ñ¥Æ¥£
+    ¤ò´Þ¤àʸ»ú¥Æ¡¼¥Ö¥ë¤òÊÖ¤¹¡£¤â¤· $TYPE ¤¬ NULL ¤Ç¤Ê¤±¤ì¤Ð¡¢ $TYPE ¤Ç
+    »Ø¤µ¤ì¤ë¾ì½ê¤Ë¤½¤Îʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤ò³ÊǼ¤¹¤ë¡£Ê¸»ú¥×¥í¥Ñ¥Æ¥£¤Î¼ïÎà
+    ¤Ë´Ø¤·¤Æ¤Ï mchar_define_property () ¤ò¸«¤è¡£
+
+    @return
+    ¤â¤· $KEY ¤¬ÀµÅö¤Êʸ»ú¥×¥í¥Ñ¥Æ¥£¤Î¥­¡¼¤Ç¤¢¤ì¤Ð¡¢Ê¸»ú¥Æ¡¼¥Ö¥ë¤¬ÊÖ¤µ
+    ¤ì¤ë¡£¤½¤¦¤Ç¤Ê¤¤¾ì¹ç¤Ï NULL ¤¬ÊÖ¤µ¤ì¤ë¡£  */
 
 MCharTable *
 mchar_get_prop_table (MSymbol key, MSymbol *type)
 {
   MCharPropRecord *record;
 
+  if (! char_prop_list)
+    return NULL;
   record = mplist_get (char_prop_list, key);
   if (! record)
     return NULL;
   if (record->mdb)
     {
-      record->table = (*mdatabase__loader) (record->mdb);
+      record->table = mdatabase_load (record->mdb);
       if (! record->table)
        MERROR (MERROR_DB, NULL);
       record->mdb = NULL;