-/* $Id: tst_icu_I18N.c,v 1.10 2007-10-29 10:22:23 marc Exp $
- Copyright (c) 2006-2007, Index Data.
-
- This file is part of Pazpar2.
-
- Pazpar2 is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free
- Software Foundation; either version 2, or (at your option) any later
- version.
-
- Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- for more details.
-
- You should have received a copy of the GNU General Public License
- along with Pazpar2; see the file LICENSE. If not, write to the
- Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
-*/
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) 1995-2009 Index Data
+ * See the file LICENSE for details.
+ */
/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
#include <yaz/test.h>
-#if HAVE_ICU
+#if YAZ_HAVE_ICU
#include <yaz/icu_I18N.h>
#include <string.h>
struct icu_buf_utf16 * src16 = icu_buf_utf16_create(0);
struct icu_buf_utf16 * dest16 = icu_buf_utf16_create(0);
struct icu_buf_utf8 * dest8 = icu_buf_utf8_create(0);
- struct icu_normalizer * normalizer
- = icu_normalizer_create(rules8cstr, 'f', &status);
+ struct icu_transform * transform
+ = icu_transform_create(rules8cstr, 'f', 0, &status);
icu_check_status(status);
icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
icu_check_status(status);
- icu_normalizer_normalize(normalizer, dest16, src16, &status);
+ icu_transform_trans(transform, dest16, src16, &status);
icu_check_status(status);
icu_utf16_to_utf8(dest8, dest16, &status);
}
- icu_normalizer_destroy(normalizer);
+ icu_transform_destroy(transform);
icu_buf_utf16_destroy(src16);
icu_buf_utf16_destroy(dest16);
icu_buf_utf8_destroy(dest8);
struct icu_chain * chain = 0;
- const char * xml_str = "<icu>"
- "<normalize rule=\"[:Control:] Any-Remove\"/>"
+ const char * xml_str = "<icu locale=\"en\">"
+ "<transform rule=\"[:Control:] Any-Remove\"/>"
"<tokenize rule=\"l\"/>"
- "<normalize rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+ "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
"<display/>"
"<casemap rule=\"l\"/>"
"</icu>";
xmlNode *xml_node = xmlDocGetRootElement(doc);
YAZ_CHECK(xml_node);
- // printf("ICU chain:\ninput: '%s'\n", en_str);
-
-
- chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status);
+ chain = icu_chain_xml_config(xml_node, 0, &status);
xmlFreeDoc(doc);
YAZ_CHECK(chain);
while (icu_chain_next_token(chain, &status)){
;
- // printf("%d '%s' '%s'\n",
- // icu_chain_token_number(chain),
- // icu_chain_token_norm(chain),
- // icu_chain_token_display(chain));
+ /* printf("%d '%s' '%s'\n",
+ icu_chain_token_number(chain),
+ icu_chain_token_norm(chain),
+ icu_chain_token_display(chain)); */
}
YAZ_CHECK_EQ(icu_chain_token_number(chain), 7);
while (icu_chain_next_token(chain, &status)){
;
- //printf("%d '%s' '%s'\n",
- // icu_chain_token_number(chain),
- // icu_chain_token_norm(chain),
- // icu_chain_token_display(chain));
+ /* printf("%d '%s' '%s'\n",
+ icu_chain_token_number(chain),
+ icu_chain_token_norm(chain),
+ icu_chain_token_display(chain)); */
}
UErrorCode status = U_ZERO_ERROR;
struct icu_chain * chain = 0;
- const char * xml_str = "<icu>"
+ const char * xml_str = "<icu locale=\"en\">"
/* if the first rule is normalize instead. Then it works */
#if 0
- "<normalize rule=\"[:Control:] Any-Remove\"/>"
+ "<transform rule=\"[:Control:] Any-Remove\"/>"
#endif
"<tokenize rule=\"l\"/>"
- "<normalize rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+ "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
"<display/>"
"<casemap rule=\"l\"/>"
"</icu>";
xmlNode *xml_node = xmlDocGetRootElement(doc);
YAZ_CHECK(xml_node);
- chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status);
+ chain = icu_chain_xml_config(xml_node, 0, &status);
xmlFreeDoc(doc);
YAZ_CHECK(chain);
while (icu_chain_next_token(chain, &status)){
;
- //printf("%d '%s' '%s'\n",
- // icu_chain_token_number(chain),
- // icu_chain_token_norm(chain),
- // icu_chain_token_display(chain));
+ /* printf("%d '%s' '%s'\n",
+ icu_chain_token_number(chain),
+ icu_chain_token_norm(chain),
+ icu_chain_token_display(chain)); */
}
while (icu_chain_next_token(chain, &status)){
;
- //printf("%d '%s' '%s'\n",
- // icu_chain_token_number(chain),
- // icu_chain_token_norm(chain),
- // icu_chain_token_display(chain));
+ /* printf("%d '%s' '%s'\n",
+ icu_chain_token_number(chain),
+ icu_chain_token_norm(chain),
+ icu_chain_token_display(chain)); */
}
/* we expect 'what' 'is' 'this', i.e. 3 tokens */
UErrorCode status = U_ZERO_ERROR;
struct icu_chain * chain = 0;
- const char * xml_str = "<icu>"
+ const char * xml_str = "<icu locale=\"en\">"
"<tokenize rule=\"w\"/>"
- "<normalize rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
+ "<transform rule=\"[[:WhiteSpace:][:Punctuation:]] Remove\"/>"
"</icu>";
xmlDoc *doc = xmlParseMemory(xml_str, strlen(xml_str));
xmlNode *xml_node = xmlDocGetRootElement(doc);
YAZ_CHECK(xml_node);
- chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status);
+ chain = icu_chain_xml_config(xml_node, 0, &status);
xmlFreeDoc(doc);
YAZ_CHECK(chain);
YAZ_CHECK(icu_chain_assign_cstr(
- chain, "a string with 15 wordbreaks and 8 tokens",
+ chain, "a string with 15 tokenss and 8 displays",
&status));
while (icu_chain_next_token(chain, &status)){
;
- //printf("%d '%s' '%s'\n",
- // icu_chain_token_number(chain),
- // icu_chain_token_norm(chain),
- // icu_chain_token_display(chain));
+ /* printf("%d '%s' '%s'\n",
+ icu_chain_token_number(chain),
+ icu_chain_token_norm(chain),
+ icu_chain_token_display(chain)); */
}
- YAZ_CHECK_EQ(icu_chain_token_number(chain), 8);
+ YAZ_CHECK_EQ(icu_chain_token_number(chain), 15);
icu_chain_destroy(chain);
}
UErrorCode status = U_ZERO_ERROR;
struct icu_chain * chain = 0;
- const char * xml_str = "<icu>"
+ const char * xml_str = "<icu locale=\"en\">"
"</icu>";
const char * src8 = "some 5487 weired !ยค%&(/& sTuFf";
xmlNode *xml_node = xmlDocGetRootElement(doc);
YAZ_CHECK(xml_node);
- chain = icu_chain_xml_config(xml_node, (uint8_t *) "en", 0, &status);
+ chain = icu_chain_xml_config(xml_node, 0, &status);
xmlFreeDoc(doc);
YAZ_CHECK(chain);
while (icu_chain_next_token(chain, &status)){
;
- //printf("%d '%s' '%s'\n",
- // icu_chain_token_number(chain),
- // icu_chain_token_norm(chain),
- // icu_chain_token_display(chain));
+ /* printf("%d '%s' '%s'\n",
+ icu_chain_token_number(chain),
+ icu_chain_token_norm(chain),
+ icu_chain_token_display(chain)); */
}
YAZ_CHECK_EQ(icu_chain_token_number(chain), 1);
- dest8 = icu_chain_token_norm(chain);
+ dest8 = (char *) icu_chain_token_norm(chain);
YAZ_CHECK_EQ(strcmp(src8, dest8), 0);
icu_chain_destroy(chain);
}
-#endif // HAVE_ICU
+#endif /* YAZ_HAVE_ICU */
/* DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8 */
YAZ_CHECK_INIT(argc, argv);
YAZ_CHECK_LOG();
-#if HAVE_ICU
+#if YAZ_HAVE_ICU
test_icu_I18N_casemap(argc, argv);
test_icu_I18N_sortmap(argc, argv);
test_chain_empty_chain();
test_bug_1140();
-#else /* HAVE_ICU */
+#else /* YAZ_HAVE_ICU */
printf("ICU unit tests omitted.\n"
"Please install libicu36-dev and icu-doc or similar\n");
YAZ_CHECK(0 == 0);
-#endif /* HAVE_ICU */
+#endif /* YAZ_HAVE_ICU */
YAZ_CHECK_TERM;
}
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
+