projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Refactor ICU WRT locale.
[yaz-moved-to-github.git]
/
src
/
icu_I18N.c
diff --git
a/src/icu_I18N.c
b/src/icu_I18N.c
index
efc3cfc
..
4e9dcf7
100644
(file)
--- a/
src/icu_I18N.c
+++ b/
src/icu_I18N.c
@@
-2,7
+2,7
@@
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
* Copyright (C) 1995-2007, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: icu_I18N.c,v 1.8 2007-10-25 10:04:32 marc Exp $
+ * $Id: icu_I18N.c,v 1.14 2007-11-08 13:35:13 adam Exp $
*/
#if HAVE_CONFIG_H
*/
#if HAVE_CONFIG_H
@@
-15,7
+15,7
@@
#endif
#endif
-#if HAVE_ICU
+#if YAZ_HAVE_ICU
#include <yaz/icu_I18N.h>
#include <yaz/log.h>
#include <yaz/icu_I18N.h>
#include <yaz/log.h>
@@
-267,6
+267,7
@@
UErrorCode icu_utf16_from_utf8_cstr(struct icu_buf_utf16 * dest16,
size_t src8cstr_len = 0;
int32_t utf16_len = 0;
size_t src8cstr_len = 0;
int32_t utf16_len = 0;
+ *status = U_ZERO_ERROR;
src8cstr_len = strlen(src8cstr);
u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
src8cstr_len = strlen(src8cstr);
u_strFromUTF8(dest16->utf16, dest16->utf16_cap,
@@
-332,7
+333,6
@@
struct icu_casemap * icu_casemap_create(const char *locale, char action,
{
struct icu_casemap * casemap
= (struct icu_casemap *) malloc(sizeof(struct icu_casemap));
{
struct icu_casemap * casemap
= (struct icu_casemap *) malloc(sizeof(struct icu_casemap));
- strcpy(casemap->locale, locale);
casemap->action = action;
switch(casemap->action) {
casemap->action = action;
switch(casemap->action) {
@@
-355,7
+355,7
@@
struct icu_casemap * icu_casemap_create(const char *locale, char action,
void icu_casemap_destroy(struct icu_casemap * casemap)
{
void icu_casemap_destroy(struct icu_casemap * casemap)
{
- if (casemap)
+ if (casemap)
free(casemap);
}
free(casemap);
}
@@
-363,13
+363,14
@@
void icu_casemap_destroy(struct icu_casemap * casemap)
int icu_casemap_casemap(struct icu_casemap * casemap,
struct icu_buf_utf16 * dest16,
struct icu_buf_utf16 * src16,
int icu_casemap_casemap(struct icu_casemap * casemap,
struct icu_buf_utf16 * dest16,
struct icu_buf_utf16 * src16,
- UErrorCode *status)
+ UErrorCode *status,
+ const char *locale)
{
if(!casemap)
return 0;
{
if(!casemap)
return 0;
- return icu_utf16_casemap(dest16, src16,
- casemap->locale, casemap->action, status);
+ return icu_utf16_casemap(dest16, src16, locale,
+ casemap->action, status);
}
}
@@
-850,7
+851,7
@@
void icu_chain_step_destroy(struct icu_chain_step * step){
-struct icu_chain * icu_chain_create(const uint8_t * locale,
+struct icu_chain * icu_chain_create(const char *locale,
int sort,
UErrorCode * status)
{
int sort,
UErrorCode * status)
{
@@
-858,6
+859,8
@@
struct icu_chain * icu_chain_create(const uint8_t * locale,
struct icu_chain * chain
= (struct icu_chain *) malloc(sizeof(struct icu_chain));
struct icu_chain * chain
= (struct icu_chain *) malloc(sizeof(struct icu_chain));
+ *status = U_ZERO_ERROR;
+
strncpy((char *) chain->locale, (const char *) locale, 16);
chain->locale[16 - 1] = '\0';
strncpy((char *) chain->locale, (const char *) locale, 16);
chain->locale[16 - 1] = '\0';
@@
-905,27
+908,32
@@
void icu_chain_destroy(struct icu_chain * chain)
-struct icu_chain * icu_chain_xml_config(xmlNode *xml_node,
- const uint8_t * locale,
+struct icu_chain * icu_chain_xml_config(const xmlNode *xml_node,
int sort,
int sort,
- UErrorCode * status){
-
+ UErrorCode * status)
+{
xmlNode *node = 0;
struct icu_chain * chain = 0;
xmlNode *node = 0;
struct icu_chain * chain = 0;
- if (!xml_node
- ||xml_node->type != XML_ELEMENT_NODE
- // || strcmp((const char *) xml_node->name, "icu_chain")
- )
+ *status = U_ZERO_ERROR;
+ if (!xml_node ||xml_node->type != XML_ELEMENT_NODE)
return 0;
return 0;
-
- chain = icu_chain_create(locale, sort, status);
-
+
+ {
+ xmlChar * xml_locale = xmlGetProp((xmlNode *) xml_node,
+ (xmlChar *) "locale");
+
+ if (xml_locale)
+ {
+ chain = icu_chain_create((const char *) xml_locale, sort, status);
+ xmlFree(xml_locale);
+ }
+
+ }
if (!chain)
return 0;
if (!chain)
return 0;
-
for (node = xml_node->children; node; node = node->next)
{
xmlChar *xml_rule;
for (node = xml_node->children; node; node = node->next)
{
xmlChar *xml_rule;
@@
-1035,6
+1043,7
@@
int icu_chain_step_next_token(struct icu_chain * chain,
if (step->previous){
src16 = step->previous->buf16;
/* tokens might be killed in previous steps, therefore looping */
if (step->previous){
src16 = step->previous->buf16;
/* tokens might be killed in previous steps, therefore looping */
+
while (step->need_new_token
&& step->previous->more_tokens
&& !got_new_token)
while (step->need_new_token
&& step->previous->more_tokens
&& !got_new_token)
@@
-1066,7
+1075,8
@@
int icu_chain_step_next_token(struct icu_chain * chain,
break;
case ICU_chain_step_type_casemap:
icu_casemap_casemap(step->u.casemap,
break;
case ICU_chain_step_type_casemap:
icu_casemap_casemap(step->u.casemap,
- step->buf16, src16, status);
+ step->buf16, src16, status,
+ chain->locale);
break;
case ICU_chain_step_type_normalize:
icu_normalizer_normalize(step->u.normalizer,
break;
case ICU_chain_step_type_normalize:
icu_normalizer_normalize(step->u.normalizer,
@@
-1088,8
+1098,10
@@
int icu_chain_step_next_token(struct icu_chain * chain,
/* make sure to get new previous token if this one had been used up
by recursive call to _same_ step */
/* make sure to get new previous token if this one had been used up
by recursive call to _same_ step */
- if (!step->more_tokens)
+ if (!step->more_tokens){
step->more_tokens = icu_chain_step_next_token(chain, step, status);
step->more_tokens = icu_chain_step_next_token(chain, step, status);
+ return step->more_tokens; // avoid one token count too much!
+ }
break;
default:
break;
default:
@@
-1101,11
+1113,8
@@
int icu_chain_step_next_token(struct icu_chain * chain,
return 0;
/* if token disappered into thin air, tell caller */
return 0;
/* if token disappered into thin air, tell caller */
- if (!step->buf16->utf16_len)
- return 0;
-
- if (U_FAILURE(*status))
- return 0;
+ /* if (!step->buf16->utf16_len && !step->more_tokens) */
+ /* return 0; */
return 1;
}
return 1;
}
@@
-1151,6
+1160,8
@@
int icu_chain_next_token(struct icu_chain * chain,
{
int got_token = 0;
{
int got_token = 0;
+ *status = U_ZERO_ERROR;
+
if (!chain)
return 0;
if (!chain)
return 0;
@@
-1173,7
+1184,7
@@
int icu_chain_next_token(struct icu_chain * chain,
while(!got_token && chain->steps && chain->steps->more_tokens)
got_token = icu_chain_step_next_token(chain, chain->steps, status);
while(!got_token && chain->steps && chain->steps->more_tokens)
got_token = icu_chain_step_next_token(chain, chain->steps, status);
-
+
if (got_token){
chain->token_count++;
if (got_token){
chain->token_count++;
@@
-1191,7
+1202,7
@@
int icu_chain_next_token(struct icu_chain * chain,
return 0;
}
return 0;
}
-int icu_chain_get_token_count(struct icu_chain * chain)
+int icu_chain_token_number(struct icu_chain * chain)
{
if (!chain)
return 0;
{
if (!chain)
return 0;
@@
-1200,7
+1211,7
@@
int icu_chain_get_token_count(struct icu_chain * chain)
}
}
-const char * icu_chain_get_display(struct icu_chain * chain)
+const char * icu_chain_token_display(struct icu_chain * chain)
{
if (chain->display8)
return icu_buf_utf8_to_cstr(chain->display8);
{
if (chain->display8)
return icu_buf_utf8_to_cstr(chain->display8);
@@
-1208,7
+1219,7
@@
const char * icu_chain_get_display(struct icu_chain * chain)
return 0;
}
return 0;
}
-const char * icu_chain_get_norm(struct icu_chain * chain)
+const char * icu_chain_token_norm(struct icu_chain * chain)
{
if (!chain->steps)
return chain->src8cstr;
{
if (!chain->steps)
return chain->src8cstr;
@@
-1219,7
+1230,7
@@
const char * icu_chain_get_norm(struct icu_chain * chain)
return 0;
}
return 0;
}
-const char * icu_chain_get_sort(struct icu_chain * chain)
+const char * icu_chain_token_sortkey(struct icu_chain * chain)
{
if (chain->sort8)
return icu_buf_utf8_to_cstr(chain->sort8);
{
if (chain->sort8)
return icu_buf_utf8_to_cstr(chain->sort8);
@@
-1233,9
+1244,7
@@
const UCollator * icu_chain_get_coll(struct icu_chain * chain)
}
}
-
-
-#endif /* HAVE_ICU */
+#endif /* YAZ_HAVE_ICU */