libUnihan  0.5.3
Unihan.h
Go to the documentation of this file.
1 
8 /*
9  * Copyright © 2008 Red Hat, Inc. All rights reserved.
10  * Copyright © 2008 Ding-Yi Chen <dchen at redhat dot com>
11  *
12  * This file is part of the libUnihan Project.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this program; if not, write to the
26  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
27  * Boston, MA 02111-1307 USA
28  */
29 #ifndef UNIHAN_H_
30 #define UNIHAN_H_
31 #include "Unihan_enum.h"
32 #include "Unihan_phonetic.h"
33 #include "sqlite_functions.h"
34 #include "str_functions.h"
35 
39 typedef int (*UnihanCallback)(void* userOption,int col_num,char** results,char** col_names);
40 
41 
49 typedef struct {
50  const char *name;
51  const char *description;
53 
61 typedef struct {
63  const char *sourceMapping;
65 
66 
71 typedef struct {
72  const char* funcName;
73  int argc;
74  void (*func)(sqlite3_context *context, int argc, sqlite3_value **argv);
75  void (*stepFunc)(sqlite3_context *context, int argc, sqlite3_value **argv);
76  void (*finalizeFunc)(sqlite3_context *context);
78 
83 extern const DatabaseFuncStru DATABASE_FUNCS[];
84 
95 typedef guint UnihanQueryOption;
96 
97 #define UNIHAN_QUERY_OPTION_LIKE 1
98 #define UNIHAN_QUERY_OPTION_SCALAR_STRING 1 << 1
99 #define UNIHAN_QUERY_OPTION_SHOW_GIVEN_FIELD 1 << 2
100 #define UNIHAN_QUERY_OPTION_PINYIN_TONE_ACCENT 1 << 3
101 #define UNIHAN_QUERY_OPTION_PINYIN_FORMAT_MASK 7 << 4
102 #define UNIHAN_QUERY_OPTION_ZHUYIN_FORCE_DISPLAY 1 << 7
103 #define UNIHAN_QUERY_OPTION_ZHUYIN_FORMAT_MASK 7 << 8
104 
105 #define UNIHAN_QUERY_OPTION_DEFAULT (PINYIN_ACCENT_UNIHAN << 4) | (ZHUYIN_TONEMARK_ORIGINAL << 8)
106 
114 #define UNIHAN_QUERY_OPTION_GET_PINYIN_FORMAT(options) (options & UNIHAN_QUERY_OPTION_PINYIN_FORMAT_MASK) >> 4
115 
122 #define UNIHAN_QUERY_OPTION_SET_PINYIN_FORMAT(options,format) options |= format << 4
123 
130 #define UNIHAN_QUERY_OPTION_GET_ZHUYIN_FORMAT(options) (options & UNIHAN_QUERY_OPTION_ZHUYIN_FORMAT_MASK) >> 8
131 
138 #define UNIHAN_QUERY_OPTION_SET_ZHUYIN_FORMAT(options,format) options |= format << 8
139 
165 SQL_Result *unihan_find_all_matched(UnihanField givenField, const char *givenValue,
166  UnihanField queryField, UnihanQueryOption qOption);
167 
184 char* unihan_find_firstMatched(UnihanField givenField, const char* givenValue,
185  UnihanField queryField, UnihanQueryOption qOption );
186 
202 
217 int unihan_insert(UnihanTable table,StringList *valueList);
218 
231 
255 int unihan_insert_value(gunichar code, UnihanField field, const char *value);
256 
264 gboolean unihanChar_has_property(gunichar code, UnihanField field);
265 
273 gboolean unihanChar_is_in_source(gunichar code, UnihanIRG_SourceId source);
274 
285 
298 gboolean unihanChar_is_common_in_locale(gunichar code, UnihanLocale locale);
299 
307 UnihanRange unihanChar_in_range(gunichar code);
308 
315 gunichar unihanChar_parse(const char *str);
316 
323 char *unihanChar_to_scalar_string(gunichar code);
324 
325 
333 sqlite3 *unihanDb_get();
334 
344 
345 
379 int unihanDb_open(const char *filename, int flags);
380 
390 
399 int unihanDb_close();
400 
408 int unihanField_array_index(UnihanField field, const UnihanField* fieldArray);
409 
418 
436 
449 
468 
476 gboolean unihanField_is_IRG_Source(UnihanField field);
477 
478 
489 gboolean unihanField_is_indexed(UnihanField field);
490 
497 gboolean unihanField_is_integer(UnihanField field);
498 
522 
538 gboolean unihanField_is_lowercase(UnihanField field);
539 
546 gboolean unihanField_is_mandarin(UnihanField field);
547 
565 gboolean unihanField_is_pseudo(UnihanField field);
566 
575 gboolean unihanField_is_ucs4(UnihanField field);
576 
591 gboolean unihanField_is_singleton(UnihanField field);
592 
599 UnihanField unihanField_parse(const char *str);
600 
607 const char* unihanField_to_string(UnihanField field);
608 
620 
629 
636 UnihanIRG_SourceId unihanIRG_SourceId_parse(const char *sourceShortName);
637 
648 
655 
665 int unihanSql_count_matches(const char * sqlClause, char **errMsg_ptr);
666 
678 int unihanSql_exec(char *sqlClause, UnihanCallback callback,
679  void *callbackOption, char **errMsg_ptr);
680 
688 SQL_Result *unihanSql_get_sql_result(const char *sqlClause);
689 
690 
698 
707 const char *unihanLocale_to_string(UnihanLocale locale);
708 
717 const char *unihanRange_to_string(UnihanRange uRange);
718 
725 UnihanTable unihanTable_parse(const char * tableName);
726 
735 const char *unihanTable_to_string(UnihanTable table);
736 
737 
751 
767 
778 
779 
780 
781 #endif /* UNIHAN_H */
const char * name
short source name in string. (e.g. "G0").
Definition: Unihan.h:50
UnihanField unihanField_parse(const char *str)
Parses the string argument as a UnihanField.
gboolean unihanField_is_IRG_Source(UnihanField field)
Whether the field is IRG_Source.
const char * description
full description of the IRG source. (e.g. "GB2310-80").
Definition: Unihan.h:51
UnihanRange unihanChar_in_range(gunichar code)
Return the range which the character belong to.
UnihanTable unihanField_get_table(UnihanField field)
Return the table that contains the key.
Phonetic symbols (PinYin and ZhuYin) processing functions.
UnihanTable unihanTable_parse(const char *tableName)
Parse the string argument as UnihanTable.
gboolean unihanChar_is_in_source(gunichar code, UnihanIRG_SourceId source)
Whether the character appeared in given source.
sqlite3 * unihanDb_get()
Returns the db which libUnihan is using.
UnihanIRG_SourceId unihanIRG_SourceId_parse(const char *sourceShortName)
Parse the string argument as Unihan IRG Source ID.
Data structure of database supporting functions.
Definition: Unihan.h:71
const char * unihanTable_to_string(UnihanTable table)
Returns a string representing a UnihanTable.
void unihanIRG_SourceRec_free(UnihanIRG_SourceRec *rec)
Free the UnihanIRG_SourceRec.
const char * funcName
Name to be referred in SQL.
Definition: Unihan.h:72
SQL_Result * unihan_find_all_matched(UnihanField givenField, const char *givenValue, UnihanField queryField, UnihanQueryOption qOption)
Find all matched results, given a field and its value.
const UnihanIRG_SourceData * unihanIRG_SourceData_get(UnihanIRG_SourceId sourceId)
Return the Unihan IRG_Source Data.
guint UnihanQueryOption
Unihan query options.
Definition: Unihan.h:95
const char * unihanField_to_string(UnihanField field)
Returns a string representing a UnihanField.
gboolean unihanChar_is_common_in_locale(gunichar code, UnihanLocale locale)
Whether the character is common in the specified locale.
SQL_Result * unihanSql_get_sql_result(const char *sqlClause)
Obtains a SQL_Result table of SQL command.
int unihanSql_count_matches(const char *sqlClause, char **errMsg_ptr)
Count the number of matches.
StringList is a structure that stores a list of constant strings.
Definition: str_functions.h:47
String processing functions.
int(* UnihanCallback)(void *userOption, int col_num, char **results, char **col_names)
Prototype of callback function for SQL execution.
Definition: Unihan.h:39
int argc
Number of arguments.
Definition: Unihan.h:73
int unihan_insert_value(gunichar code, UnihanField field, const char *value)
Insert a Unihan textual formated record to corresponding tables.
UnihanIRG_Source unihanField_get_IRG_source(UnihanField field)
Return the corresponding IRG source if the field is IRG source field.
gboolean unihanField_is_pseudo(UnihanField field)
Whether the field is a pseudo field.
int unihan_insert(UnihanTable table, StringList *valueList)
Insert a record to table.
gunichar unihanChar_parse(const char *str)
Parses the string argument as a UCS4 (gunichar) character.
int unihanDb_open(const char *filename, int flags)
Open a Unihan db.
gboolean unihanChar_has_property(gunichar code, UnihanField field)
Whether the character is associate with the given field.
int unihanSql_exec(char *sqlClause, UnihanCallback callback, void *callbackOption, char **errMsg_ptr)
Execute the SQL to Unihan db.
const char * unihanRange_to_string(UnihanRange uRange)
Returns a string representing a UnihanLocale.
gboolean unihanField_is_singleton(UnihanField field)
Whether the field is a singleton field.
const char * unihanLocale_to_string(UnihanLocale locale)
Returns a string representing a UnihanLocale.
int unihan_insert_no_duplicate(UnihanTable table, StringList *valueList)
Insert a record to table with duplication check.
UnihanIRG_SourceId unihanChar_is_in_sources(gunichar code, UnihanIRG_SourceId source,...)
Find the first source which the character appears in.
int unihanDb_open_default()
Open the system default Unihan Db as read-only.
const DatabaseFuncStru DATABASE_FUNCS[]
List of database supporting functions.
UnihanIRG_SourceId
Enumeration of IRG Source ID.
Definition: Unihan_enum.h:378
UnihanField * unihanTable_get_primary_key_fields(UnihanTable table)
Returns all primary key fields of the given table in an UnihanField array.
Data structure that holds the result of SQL functions and command.
Definition: sqlite_functions.h:146
gboolean unihanIRG_Source_has_no_mapping(UnihanIRG_SourceId sourceId)
Whether the SourceId has mapping.
gboolean unihanField_is_lowercase(UnihanField field)
Whether the value in the field is stored as lowercase.
const char * sourceMapping
the mapping of the character in the source.
Definition: Unihan.h:63
UnihanField * unihanTable_get_db_fields(UnihanTable table)
Returns the actual data table fields in an UnihanField array.
gboolean unihanField_is_case_no_change(UnihanField field)
Whether the case of value should be kept.
SQLite suppporting data structures and functions.
UnihanIRG_SourceRec * unihanIRG_SourceRec_parse(UnihanField field, const char *value)
Parse the string argument as Unihan IRG Source Rec.
SQL_Result * unihanDb_get_tableNames()
Returns the tables in database.
UnihanRange
Enumeration of Unihan Range.
Definition: Unihan_enum.h:467
IRG source data.
Definition: Unihan.h:49
UnihanTable
Enumeration of tables.
Definition: Unihan_enum.h:248
UnihanField
Enumeration of Unihan fields.
Definition: Unihan_enum.h:67
gboolean unihanField_is_indexed(UnihanField field)
Whether the field is indexed.
UnihanField * unihanTable_get_fields(UnihanTable table)
Returns all fields of the table in an UnihanField array.
int unihanField_array_index(UnihanField field, const UnihanField *fieldArray)
Return the index of a UnihanField in array.
IRG source rec.
Definition: Unihan.h:61
char * unihanChar_to_scalar_string(gunichar code)
Returns a string representing a UCS4 character.
UnihanLocale unihanLocale_parse(char *str)
Parse the string argument as Unihan Locale.
Enumeration and defintion used in libUnihan.
UnihanTable unihanField_get_extra_table(UnihanField field)
Return the corresponding extra table if the field needs one.
UnihanLocale
Enumeration of supported locales.
Definition: Unihan_enum.h:442
UnihanIRG_SourceId sourceId
a IRG source ID.
Definition: Unihan.h:62
UnihanTable * unihanField_get_all_tables(UnihanField field)
Return all the tables that contains the key.
char * unihan_find_firstMatched(UnihanField givenField, const char *givenValue, UnihanField queryField, UnihanQueryOption qOption)
Find the first matched result, given a field and its value.
gboolean unihanField_is_ucs4(UnihanField field)
Whether the field holds UCS4 value.
int unihanDb_close()
Close Unihan db.
gboolean unihanField_is_mandarin(UnihanField field)
Whether the field contains mandarin pronunciation.
gboolean unihanField_is_integer(UnihanField field)
Whether the field is an integer field.
int unihan_count_matched_record(UnihanTable table, StringList *valueList)
Count number of matched records in a table.
UnihanIRG_Source
Enumeration of IRG Source.
Definition: Unihan_enum.h:354