-/* $Id: test_icu_I18N.c,v 1.14 2007-05-10 12:11:42 marc Exp $
+/* $Id: test_icu_I18N.c,v 1.18 2007-05-11 22:59:36 marc Exp $
Copyright (c) 2006-2007, Index Data.
This file is part of Pazpar2.
printf("\n");
}
-
+
+
+ for( i = 0; i < src_list_len; i++)
+ free(list[i]);
+
+
ucol_close(coll);
icu_buf_utf8_destroy(buf8);
icu_buf_utf16_destroy(buf16);
-
-
return success;
}
// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
-void test_icu_I18N_transliterator(int argc, char **argv)
+int test_icu_transliterator(const char * rules8cstr,
+ const char * src8cstr,
+ const char * chk8cstr)
{
+ int success = 0;
+
+ UErrorCode status = U_ZERO_ERROR;
+ UParseError parse_error[256];
- /* setting up transliterator */
-#if 0
+ struct icu_buf_utf16 * rules16 = icu_buf_utf16_create(0);
+ 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);
- UErrorCode status = U_ZERO_ERROR;
- UParseError parse_error[256];
+ icu_utf16_from_utf8_cstr(rules16, rules8cstr, &status);
+ icu_check_status(status);
- int32_t id_cap = 256;
- UChar id[256];
- id[0] = 0;
+ icu_utf16_from_utf8_cstr(src16, src8cstr, &status);
+ icu_check_status(status);
- trans = utrans_openU(id, id_len, UTRANS_FORWARD,
- 0, 0, parse_error, &status);
-
-
+ UTransliterator * trans
+ = utrans_openU(rules16->utf16, rules16->utf16_len,
+ UTRANS_FORWARD,
+ 0, 0,
+ parse_error, &status);
+
+ //= utrans_openU(0, 0, UTRANS_FORWARD,
+ // rules16->utf16, rules16->utf16_len,
+ // parse_error, &status);
+
+ icu_check_status(status);
if(U_FAILURE(status)) {
- printf("Parse Error: line %d offset %d \n",
- parse_error->line, parse_error->offset);
+ printf("Parse Error: \n line %d offset %d \n '%s'\n",
+ parse_error->line, parse_error->offset,
+ rules8cstr);
}
+
+ utrans_transUChars (trans, src16->utf16, &(src16->utf16_len),
+ src16->utf16_cap,
+ 0, &(src16->utf16_len), &status);
+
+ icu_utf16_to_utf8(dest8, src16, &status);
icu_check_status(status);
- int32_t ustr16_lim = *ustr16_len;
- /* Transliterate a segment of a UChar* string */
-
- utrans_transUChars (trans, ustr16, &*ustr16_len,
- ustr16_cap,
- 0, &ustr16_lim, &status);
+ if(!strcmp((const char *) dest8->utf8,
+ (const char *) chk8cstr))
+ success = 1;
+ else {
+ success = 0;
+ printf("Normaliozation;");
+ printf("Rules: '%s'\n", rules8cstr);
+ printf("Input: '%s'\n", src8cstr);
+ printf("Normalized: '%s'\n", dest8->utf8);
+ printf("Expected: '%s'\n", chk8cstr);
+ }
+
utrans_close (trans);
+ icu_buf_utf16_destroy(rules16);
+ icu_buf_utf16_destroy(src16);
+ icu_buf_utf16_destroy(dest16);
+ icu_buf_utf8_destroy(dest8);
+ return success;
+}
+
+#if 0
printf("\n\nUnicode Set Patterns:\n"
" Pattern Description\n"
" Ranges [a-z] The lower case letters a through z\n"
" Named Chars [abc123] The six characters a,b,c,1,2 and 3\n"
- " String [abc{def}] chars a, b and c, and string 'def'\n
-"
- " Categories [\\p{Letter}] Perl General Category 'Letter'.\n
-"
+ " String [abc{def}] chars a, b and c, and string 'def'\n"
+ " Categories [\\p{Letter}] Perl General Category 'Letter'.\n"
" Categories [:Letter:] Posix General Category 'Letter'.\n"
"\n"
" Combination Example\n"
" Lower; [:^Letter:] Remove (word tokenization)\n"
" [:^Number:] Remove (numeric tokenization)\n"
" [:^Katagana:] Remove (remove everything except Katagana)\n"
- " Lower;[[:WhiteSpace:][:Punctuation:]] Remove (word tokenization
-)\n"
- " NFD; [:Nonspacing Mark:] Remove; NFC (removes accents from ch
-aracters)\n"
- " [A-Za-z]; Lower(); Latin-Katakana; Katakana-Hiragana (transform
-s latin and katagana to hiragana)\n"
- " [[:separator:][:start punctuation:][:initial punctuation:]] Rem
-ove \n"
+ " Lower;[[:WhiteSpace:][:Punctuation:]] Remove (word tokenization)\n"
+ " NFD; [:Nonspacing Mark:] Remove; NFC (removes accents from characters)\n"
+ " [A-Za-z]; Lower(); Latin-Katakana; Katakana-Hiragana (transforms latin and katagana to hiragana)\n"
+ " [[:separator:][:start punctuation:][:initial punctuation:]] Remove \n"
"\n"
"see http://icu.sourceforge.net/userguide/Transform.html\n"
" http://www.unicode.org/Public/UNIDATA/UCD.html\n"
);
#endif
+
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
+void test_icu_I18N_transliterator(int argc, char **argv)
+{
+
+ YAZ_CHECK(test_icu_transliterator("[:Punctuation:] Any-Remove",
+ "Don't shoot!",
+ "Dont shoot"));
+
+ YAZ_CHECK(test_icu_transliterator("[:Control:] Any-Remove",
+ "Don't\n shoot!",
+ "Don't shoot!"));
+
+ YAZ_CHECK(test_icu_transliterator("[:Decimal_Number:] Any-Remove",
+ "This is 4 you!",
+ "This is you!"));
+
+ YAZ_CHECK(test_icu_transliterator("Lower; [:^Letter:] Remove",
+ "Don't shoot!",
+ "dontshoot"));
+
+ YAZ_CHECK(test_icu_transliterator("[:^Number:] Remove",
+ "Monday 15th of April",
+ "15"));
+
+ YAZ_CHECK(test_icu_transliterator("Lower;"
+ "[[:WhiteSpace:][:Punctuation:]] Remove",
+ " word4you? ",
+ "word4you"));
+
+
+ YAZ_CHECK(test_icu_transliterator("NFD; [:Nonspacing Mark:] Remove; NFC",
+ "à côté de l'alcôve ovoïde",
+ "a cote de l'alcove ovoide"));
+
}
+
+// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
+
int test_icu_tokenizer(const char * locale, char action,
const char * src8cstr, int count)
{
-// CRAP to follow
-#if 0
-
-// DO NOT EDIT THIS FILE IF YOUR EDITOR DOES NOT SUPPORT UTF-8
-
-void test_icu_I18N_casemap_failures(int argc, char **argv)
-{
-
- size_t buf_cap = 128;
- char buf[buf_cap];
- size_t dest8_len = 0;
- NMEM nmem = nmem_create();
- char * dest8 = 0;
-
- const char * src8 = "A ReD fOx hunTS sQUirriLs";
- //size_t src8_len = strlen(src8);
-
- //printf("original string: '%s' (%d)\n", src8, (int) src8_len);
-
- // some calling error needs investigation
- dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
- src8, "en", 't');
- YAZ_CHECK(0 == dest8_len);
- //printf("icu_casemap 'en:t' '%s' (%d)\n", dest8, (int) dest8_len);
-
-
- // attention: does not fail even if no locale 'xy_zz' defined
- // it seems to default to english locale
- dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
- src8, "zz_abc", 'l');
- YAZ_CHECK(dest8_len);
- //printf("icu_casemap 'zz:l' '%s' (%d)\n", dest8, (int) dest8_len);
-
-
- // shall fail - no buf buffer defined
- dest8 = icu_casemap(nmem, 0, buf_cap, &dest8_len,
- src8, "en", 'l');
- YAZ_CHECK(0 == dest8_len);
- //printf("icu_casemap 'en:l' '%s' (%d)\n", dest8, (int) dest8_len);
-
- // shall fail - no buf_cap defined
- dest8 = icu_casemap(nmem, buf, 0, &dest8_len,
- src8, "en", 'l');
- YAZ_CHECK(0 == dest8_len);
- //printf("icu_casemap 'en:l' '%s' (%d)\n", dest8, (int) dest8_len);
-
- // shall fail - no action 'x' defined
- dest8 = icu_casemap(nmem, buf, buf_cap, &dest8_len,
- src8, "en", 'x');
- YAZ_CHECK(0 == dest8_len);
- //printf("icu_casemap 'en:x' '%s' (%d)\n", dest8, (int) dest8_len);
-
- nmem_destroy(nmem);
-}
-
-
-
-#endif
-
-
-
/*
* Local variables:
* c-basic-offset: 4