2000-01-15 02:00:06 +00:00
|
|
|
/********************************************************************
|
2001-04-18 19:31:05 +00:00
|
|
|
* COPYRIGHT:
|
2008-02-16 01:31:32 +00:00
|
|
|
* Copyright (c) 1997-2008, International Business Machines Corporation and
|
2000-01-15 02:00:06 +00:00
|
|
|
* others. All Rights Reserved.
|
|
|
|
********************************************************************/
|
|
|
|
/********************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File CITERTST.C
|
|
|
|
*
|
|
|
|
* Modification History:
|
2001-04-18 19:31:05 +00:00
|
|
|
* Date Name Description
|
2001-02-23 23:41:16 +00:00
|
|
|
* Madhu Katragadda Ported for C API
|
|
|
|
* 02/19/01 synwee Modified test case for new collation iterator
|
2000-08-14 23:35:57 +00:00
|
|
|
*********************************************************************************/
|
1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
* Collation Iterator tests.
|
|
|
|
* (Let me reiterate my position...)
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-09-20 17:54:45 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_COLLATION
|
|
|
|
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ucol.h"
|
|
|
|
#include "unicode/uloc.h"
|
2001-02-23 23:41:16 +00:00
|
|
|
#include "unicode/uchar.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
2004-09-23 00:24:36 +00:00
|
|
|
#include "unicode/putil.h"
|
2003-07-22 16:45:58 +00:00
|
|
|
#include "callcoll.h"
|
2001-02-23 23:41:16 +00:00
|
|
|
#include "cmemory.h"
|
2001-04-03 00:32:05 +00:00
|
|
|
#include "cintltst.h"
|
|
|
|
#include "citertst.h"
|
|
|
|
#include "ccolltst.h"
|
2001-05-14 18:58:36 +00:00
|
|
|
#include "filestrm.h"
|
|
|
|
#include "cstring.h"
|
|
|
|
#include "ucol_imp.h"
|
2001-05-25 16:54:33 +00:00
|
|
|
#include "ucol_tok.h"
|
2001-06-12 15:54:05 +00:00
|
|
|
#include <stdio.h>
|
2001-05-25 16:54:33 +00:00
|
|
|
|
|
|
|
extern uint8_t ucol_uprv_getCaseBits(const UChar *, uint32_t, UErrorCode *);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
void addCollIterTest(TestNode** root)
|
|
|
|
{
|
|
|
|
addTest(root, &TestPrevious, "tscoll/citertst/TestPrevious");
|
|
|
|
addTest(root, &TestOffset, "tscoll/citertst/TestOffset");
|
|
|
|
addTest(root, &TestSetText, "tscoll/citertst/TestSetText");
|
2001-02-24 02:21:31 +00:00
|
|
|
addTest(root, &TestMaxExpansion, "tscoll/citertst/TestMaxExpansion");
|
2001-02-23 23:41:16 +00:00
|
|
|
addTest(root, &TestUnicodeChar, "tscoll/citertst/TestUnicodeChar");
|
2001-04-18 19:31:05 +00:00
|
|
|
addTest(root, &TestNormalizedUnicodeChar,
|
2001-04-17 17:27:37 +00:00
|
|
|
"tscoll/citertst/TestNormalizedUnicodeChar");
|
2001-04-26 01:14:28 +00:00
|
|
|
addTest(root, &TestNormalization, "tscoll/citertst/TestNormalization");
|
2001-04-07 00:20:32 +00:00
|
|
|
addTest(root, &TestBug672, "tscoll/citertst/TestBug672");
|
2001-04-28 00:25:47 +00:00
|
|
|
addTest(root, &TestBug672Normalize, "tscoll/citertst/TestBug672Normalize");
|
2001-04-17 17:27:37 +00:00
|
|
|
addTest(root, &TestSmallBuffer, "tscoll/citertst/TestSmallBuffer");
|
2001-05-14 18:58:36 +00:00
|
|
|
addTest(root, &TestCEs, "tscoll/citertst/TestCEs");
|
|
|
|
addTest(root, &TestDiscontiguos, "tscoll/citertst/TestDiscontiguos");
|
2001-05-17 21:35:14 +00:00
|
|
|
addTest(root, &TestCEBufferOverflow, "tscoll/citertst/TestCEBufferOverflow");
|
2001-05-25 16:54:33 +00:00
|
|
|
addTest(root, &TestCEValidity, "tscoll/citertst/TestCEValidity");
|
|
|
|
addTest(root, &TestSortKeyValidity, "tscoll/citertst/TestSortKeyValidity");
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-04-17 21:53:30 +00:00
|
|
|
/* The locales we support */
|
2001-04-07 00:20:32 +00:00
|
|
|
|
2001-05-04 00:02:24 +00:00
|
|
|
static const char * LOCALES[] = {"en_AU", "en_BE", "en_CA"};
|
2001-04-07 00:20:32 +00:00
|
|
|
|
|
|
|
static void TestBug672() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar pattern[20];
|
|
|
|
UChar text[50];
|
|
|
|
int i;
|
|
|
|
int result[3][3];
|
|
|
|
|
|
|
|
u_uastrcpy(pattern, "resume");
|
|
|
|
u_uastrcpy(text, "Time to resume updating my resume.");
|
|
|
|
|
|
|
|
for (i = 0; i < 3; ++ i) {
|
|
|
|
UCollator *coll = ucol_open(LOCALES[i], &status);
|
|
|
|
UCollationElements *pitr = ucol_openElements(coll, pattern, -1,
|
|
|
|
&status);
|
|
|
|
UCollationElements *titer = ucol_openElements(coll, text, -1,
|
|
|
|
&status);
|
|
|
|
if (U_FAILURE(status)) {
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of either the collator or the collation iterator :%s\n",
|
2001-04-07 00:20:32 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-07 00:20:32 +00:00
|
|
|
log_verbose("locale tested %s\n", LOCALES[i]);
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
while (ucol_next(pitr, &status) != UCOL_NULLORDER &&
|
2001-04-07 00:20:32 +00:00
|
|
|
U_SUCCESS(status)) {
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status)) {
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: reversing collation iterator :%s\n",
|
2001-04-07 00:20:32 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ucol_reset(pitr);
|
|
|
|
|
|
|
|
ucol_setOffset(titer, u_strlen(pattern), &status);
|
|
|
|
if (U_FAILURE(status)) {
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: setting offset in collator :%s\n",
|
2001-04-07 00:20:32 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result[i][0] = ucol_getOffset(titer);
|
|
|
|
log_verbose("Text iterator set to offset %d\n", result[i][0]);
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-07 00:20:32 +00:00
|
|
|
/* Use previous() */
|
|
|
|
ucol_previous(titer, &status);
|
|
|
|
result[i][1] = ucol_getOffset(titer);
|
|
|
|
log_verbose("Current offset %d after previous\n", result[i][1]);
|
|
|
|
|
|
|
|
/* Add one to index */
|
|
|
|
log_verbose("Adding one to current offset...\n");
|
|
|
|
ucol_setOffset(titer, ucol_getOffset(titer) + 1, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: setting offset in collator :%s\n",
|
2001-04-07 00:20:32 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result[i][2] = ucol_getOffset(titer);
|
|
|
|
log_verbose("Current offset in text = %d\n", result[i][2]);
|
2001-05-01 17:14:49 +00:00
|
|
|
ucol_closeElements(pitr);
|
|
|
|
ucol_closeElements(titer);
|
2001-04-07 00:20:32 +00:00
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uprv_memcmp(result[0], result[1], 3) != 0 ||
|
|
|
|
uprv_memcmp(result[1], result[2], 3) != 0) {
|
|
|
|
log_err("ERROR: Different locales have different offsets at the same character\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-28 00:25:47 +00:00
|
|
|
|
2001-04-30 20:51:22 +00:00
|
|
|
/* Running this test with normalization enabled showed up a bug in the incremental
|
|
|
|
normalization code. */
|
2001-04-28 00:25:47 +00:00
|
|
|
static void TestBug672Normalize() {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar pattern[20];
|
|
|
|
UChar text[50];
|
|
|
|
int i;
|
|
|
|
int result[3][3];
|
|
|
|
|
|
|
|
u_uastrcpy(pattern, "resume");
|
|
|
|
u_uastrcpy(text, "Time to resume updating my resume.");
|
|
|
|
|
|
|
|
for (i = 0; i < 3; ++ i) {
|
|
|
|
UCollator *coll = ucol_open(LOCALES[i], &status);
|
|
|
|
UCollationElements *pitr = NULL;
|
|
|
|
UCollationElements *titer = NULL;
|
|
|
|
|
|
|
|
ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
|
|
|
|
|
|
|
|
pitr = ucol_openElements(coll, pattern, -1, &status);
|
|
|
|
titer = ucol_openElements(coll, text, -1, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("ERROR: in creation of either the collator or the collation iterator :%s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("locale tested %s\n", LOCALES[i]);
|
|
|
|
|
|
|
|
while (ucol_next(pitr, &status) != UCOL_NULLORDER &&
|
|
|
|
U_SUCCESS(status)) {
|
|
|
|
}
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("ERROR: reversing collation iterator :%s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ucol_reset(pitr);
|
|
|
|
|
|
|
|
ucol_setOffset(titer, u_strlen(pattern), &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("ERROR: setting offset in collator :%s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result[i][0] = ucol_getOffset(titer);
|
|
|
|
log_verbose("Text iterator set to offset %d\n", result[i][0]);
|
|
|
|
|
|
|
|
/* Use previous() */
|
|
|
|
ucol_previous(titer, &status);
|
|
|
|
result[i][1] = ucol_getOffset(titer);
|
|
|
|
log_verbose("Current offset %d after previous\n", result[i][1]);
|
|
|
|
|
|
|
|
/* Add one to index */
|
|
|
|
log_verbose("Adding one to current offset...\n");
|
|
|
|
ucol_setOffset(titer, ucol_getOffset(titer) + 1, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("ERROR: setting offset in collator :%s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
result[i][2] = ucol_getOffset(titer);
|
|
|
|
log_verbose("Current offset in text = %d\n", result[i][2]);
|
2001-05-01 17:14:49 +00:00
|
|
|
ucol_closeElements(pitr);
|
|
|
|
ucol_closeElements(titer);
|
2001-04-28 00:25:47 +00:00
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uprv_memcmp(result[0], result[1], 3) != 0 ||
|
|
|
|
uprv_memcmp(result[1], result[2], 3) != 0) {
|
|
|
|
log_err("ERROR: Different locales have different offsets at the same character\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-02-23 23:41:16 +00:00
|
|
|
/**
|
|
|
|
* Test for CollationElementIterator previous and next for the whole set of
|
|
|
|
* unicode characters.
|
|
|
|
*/
|
|
|
|
static void TestUnicodeChar()
|
|
|
|
{
|
2001-03-16 18:21:49 +00:00
|
|
|
UChar source[0x100];
|
2001-02-23 23:41:16 +00:00
|
|
|
UCollator *en_us;
|
|
|
|
UCollationElements *iter;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar codepoint;
|
|
|
|
|
|
|
|
UChar *test;
|
|
|
|
en_us = ucol_open("en_US", &status);
|
2001-04-26 01:14:28 +00:00
|
|
|
if (U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collation data using ucol_open()\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-02-23 23:41:16 +00:00
|
|
|
for (codepoint = 1; codepoint < 0xFFFE;)
|
|
|
|
{
|
|
|
|
test = source;
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
while (codepoint % 0xFF != 0)
|
2001-02-23 23:41:16 +00:00
|
|
|
{
|
|
|
|
if (u_isdefined(codepoint))
|
|
|
|
*(test ++) = codepoint;
|
|
|
|
codepoint ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u_isdefined(codepoint))
|
|
|
|
*(test ++) = codepoint;
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-02-23 23:41:16 +00:00
|
|
|
if (codepoint != 0xFFFF)
|
|
|
|
codepoint ++;
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
*test = 0;
|
2001-02-23 23:41:16 +00:00
|
|
|
iter=ucol_openElements(en_us, source, u_strlen(source), &status);
|
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
2001-02-23 23:41:16 +00:00
|
|
|
myErrorName(status));
|
2001-04-26 01:14:28 +00:00
|
|
|
ucol_close(en_us);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* A basic test to see if it's working at all */
|
2001-05-17 01:07:10 +00:00
|
|
|
log_verbose("codepoint testing %x\n", codepoint);
|
2001-04-26 01:14:28 +00:00
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
|
|
|
|
/* null termination test */
|
|
|
|
iter=ucol_openElements(en_us, source, -1, &status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
ucol_close(en_us);
|
2001-02-23 23:41:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* A basic test to see if it's working at all */
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
ucol_close(en_us);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-04-17 17:27:37 +00:00
|
|
|
/**
|
|
|
|
* Test for CollationElementIterator previous and next for the whole set of
|
|
|
|
* unicode characters with normalization on.
|
|
|
|
*/
|
|
|
|
static void TestNormalizedUnicodeChar()
|
|
|
|
{
|
|
|
|
UChar source[0x100];
|
|
|
|
UCollator *th_th;
|
|
|
|
UCollationElements *iter;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar codepoint;
|
|
|
|
|
|
|
|
UChar *test;
|
|
|
|
/* thai should have normalization on */
|
|
|
|
th_th = ucol_open("th_TH", &status);
|
2001-04-26 01:14:28 +00:00
|
|
|
if (U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of thai collation using ucol_open()\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
2001-05-14 18:58:36 +00:00
|
|
|
|
2001-04-17 17:27:37 +00:00
|
|
|
for (codepoint = 1; codepoint < 0xFFFE;)
|
|
|
|
{
|
|
|
|
test = source;
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
while (codepoint % 0xFF != 0)
|
2001-04-17 17:27:37 +00:00
|
|
|
{
|
|
|
|
if (u_isdefined(codepoint))
|
|
|
|
*(test ++) = codepoint;
|
|
|
|
codepoint ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (u_isdefined(codepoint))
|
|
|
|
*(test ++) = codepoint;
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-17 17:27:37 +00:00
|
|
|
if (codepoint != 0xFFFF)
|
|
|
|
codepoint ++;
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
*test = 0;
|
2001-04-17 17:27:37 +00:00
|
|
|
iter=ucol_openElements(th_th, source, u_strlen(source), &status);
|
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
2001-04-17 17:27:37 +00:00
|
|
|
myErrorName(status));
|
|
|
|
ucol_close(th_th);
|
|
|
|
return;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-04-17 17:27:37 +00:00
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
2001-04-26 01:14:28 +00:00
|
|
|
|
|
|
|
iter=ucol_openElements(th_th, source, -1, &status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
ucol_close(th_th);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
2001-04-17 17:27:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ucol_close(th_th);
|
|
|
|
}
|
|
|
|
|
2001-04-26 01:14:28 +00:00
|
|
|
/**
|
|
|
|
* Test the incremental normalization
|
|
|
|
*/
|
|
|
|
static void TestNormalization()
|
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-11-02 02:24:15 +00:00
|
|
|
const char *str =
|
2001-04-26 01:14:28 +00:00
|
|
|
"&a < \\u0300\\u0315 < A\\u0300\\u0315 < \\u0316\\u0315B < \\u0316\\u0300\\u0315";
|
|
|
|
UCollator *coll;
|
|
|
|
UChar rule[50];
|
|
|
|
int rulelen = u_unescape(str, rule, 50);
|
|
|
|
int count = 0;
|
|
|
|
const char *testdata[] =
|
2001-05-14 18:58:36 +00:00
|
|
|
{"\\u1ED9", "o\\u0323\\u0302",
|
|
|
|
"\\u0300\\u0315", "\\u0315\\u0300",
|
2001-04-26 01:14:28 +00:00
|
|
|
"A\\u0300\\u0315B", "A\\u0315\\u0300B",
|
|
|
|
"A\\u0316\\u0315B", "A\\u0315\\u0316B",
|
|
|
|
"\\u0316\\u0300\\u0315", "\\u0315\\u0300\\u0316",
|
|
|
|
"A\\u0316\\u0300\\u0315B", "A\\u0315\\u0300\\u0316B",
|
|
|
|
"\\u0316\\u0315\\u0300", "A\\u0316\\u0315\\u0300B"};
|
2001-05-21 23:41:44 +00:00
|
|
|
int32_t srclen;
|
2001-05-14 18:58:36 +00:00
|
|
|
UChar source[10];
|
|
|
|
UCollationElements *iter;
|
2001-05-01 17:14:49 +00:00
|
|
|
|
2001-09-22 01:17:26 +00:00
|
|
|
coll = ucol_openRules(rule, rulelen, UCOL_ON, UCOL_TERTIARY, NULL, &status);
|
2001-04-26 01:14:28 +00:00
|
|
|
ucol_setAttribute(coll, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
|
|
|
|
if (U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collator using ucol_openRules()\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-14 18:58:36 +00:00
|
|
|
srclen = u_unescape(testdata[0], source, 10);
|
2003-03-13 17:20:37 +00:00
|
|
|
iter = ucol_openElements(coll, source, srclen, &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-14 18:58:36 +00:00
|
|
|
srclen = u_unescape(testdata[1], source, 10);
|
2003-03-13 17:20:37 +00:00
|
|
|
iter = ucol_openElements(coll, source, srclen, &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-04-26 01:14:28 +00:00
|
|
|
while (count < 12) {
|
|
|
|
srclen = u_unescape(testdata[count], source, 10);
|
2003-03-13 17:20:37 +00:00
|
|
|
iter = ucol_openElements(coll, source, srclen, &status);
|
2001-04-26 01:14:28 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collator element iterator\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
|
|
|
|
iter = ucol_openElements(coll, source, -1, &status);
|
|
|
|
|
|
|
|
if (U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collator element iterator\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/**
|
|
|
|
* Test for CollationElementIterator.previous()
|
|
|
|
*
|
|
|
|
* @bug 4108758 - Make sure it works with contracting characters
|
2001-04-18 19:31:05 +00:00
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestPrevious()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-03-09 18:16:37 +00:00
|
|
|
UCollator *coll=NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
UChar rule[50];
|
|
|
|
UChar *source;
|
|
|
|
UCollator *c1, *c2, *c3;
|
|
|
|
UCollationElements *iter;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2008-02-16 01:31:32 +00:00
|
|
|
UChar test1[50];
|
|
|
|
UChar test2[50];
|
2001-04-18 19:31:05 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
u_uastrcpy(test1, "What subset of all possible test cases?");
|
|
|
|
u_uastrcpy(test2, "has the highest probability of detecting");
|
2001-04-12 00:07:00 +00:00
|
|
|
coll = ucol_open("en_US", &status);
|
2000-08-28 21:43:03 +00:00
|
|
|
|
2001-03-09 18:16:37 +00:00
|
|
|
iter=ucol_openElements(coll, test1, u_strlen(test1), &status);
|
2001-05-01 17:14:49 +00:00
|
|
|
log_verbose("English locale testing back and forth\n");
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
2001-03-09 18:16:37 +00:00
|
|
|
ucol_close(coll);
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* A basic test to see if it's working at all */
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
2001-03-09 18:16:37 +00:00
|
|
|
ucol_close(coll);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Test with a contracting character sequence */
|
2001-03-03 04:09:09 +00:00
|
|
|
u_uastrcpy(rule, "&a,A < b,B < c,C, d,D < z,Z < ch,cH,Ch,CH");
|
2001-09-22 01:17:26 +00:00
|
|
|
c1 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status);
|
2001-02-26 20:02:00 +00:00
|
|
|
|
2001-05-01 17:14:49 +00:00
|
|
|
log_verbose("Contraction rule testing back and forth with no normalization\n");
|
2001-11-02 02:24:15 +00:00
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c1 == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("Couldn't create a RuleBasedCollator with a contracting sequence\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
source=(UChar*)malloc(sizeof(UChar) * 20);
|
|
|
|
u_uastrcpy(source, "abchdcba");
|
|
|
|
iter=ucol_openElements(c1, source, u_strlen(source), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(c1);
|
2001-11-02 02:24:15 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Test with an expanding character sequence */
|
2001-03-03 04:09:09 +00:00
|
|
|
u_uastrcpy(rule, "&a < b < c/abd < d");
|
2001-09-22 01:17:26 +00:00
|
|
|
c2 = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL, &status);
|
2001-05-01 17:14:49 +00:00
|
|
|
log_verbose("Expansion rule testing back and forth with no normalization\n");
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c2 == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("Couldn't create a RuleBasedCollator with a contracting sequence.\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u_uastrcpy(source, "abcd");
|
|
|
|
iter=ucol_openElements(c2, source, u_strlen(source), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(c2);
|
|
|
|
/* Now try both */
|
2001-03-03 04:09:09 +00:00
|
|
|
u_uastrcpy(rule, "&a < b < c/aba < d < z < ch");
|
2001-09-22 01:17:26 +00:00
|
|
|
c3 = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT, UCOL_DEFAULT_STRENGTH,NULL, &status);
|
2001-05-01 17:14:49 +00:00
|
|
|
log_verbose("Expansion/contraction rule testing back and forth with no normalization\n");
|
|
|
|
|
1999-10-18 22:48:32 +00:00
|
|
|
if (c3 == NULL || U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("Couldn't create a RuleBasedCollator with a contracting sequence.\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
u_uastrcpy(source, "abcdbchdc");
|
|
|
|
iter=ucol_openElements(c3, source, u_strlen(source), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(c3);
|
2001-03-09 18:16:37 +00:00
|
|
|
source[0] = 0x0e41;
|
|
|
|
source[1] = 0x0e02;
|
|
|
|
source[2] = 0x0e41;
|
|
|
|
source[3] = 0x0e02;
|
|
|
|
source[4] = 0x0e27;
|
|
|
|
source[5] = 0x61;
|
|
|
|
source[6] = 0x62;
|
|
|
|
source[7] = 0x63;
|
|
|
|
source[8] = 0;
|
|
|
|
|
|
|
|
coll = ucol_open("th_TH", &status);
|
2001-05-01 17:14:49 +00:00
|
|
|
log_verbose("Thai locale testing back and forth with normalization\n");
|
2001-03-09 18:16:37 +00:00
|
|
|
iter=ucol_openElements(coll, source, u_strlen(source), &status);
|
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
2001-03-09 18:16:37 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
|
2001-03-09 23:10:06 +00:00
|
|
|
/* prev test */
|
|
|
|
source[0] = 0x0061;
|
|
|
|
source[1] = 0x30CF;
|
|
|
|
source[2] = 0x3099;
|
|
|
|
source[3] = 0x30FC;
|
|
|
|
source[4] = 0;
|
|
|
|
|
|
|
|
coll = ucol_open("ja_JP", &status);
|
2001-05-01 17:14:49 +00:00
|
|
|
log_verbose("Japanese locale testing back and forth with normalization\n");
|
2001-03-09 23:10:06 +00:00
|
|
|
iter=ucol_openElements(coll, source, u_strlen(source), &status);
|
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
2001-03-09 23:10:06 +00:00
|
|
|
myErrorName(status));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
backAndForth(iter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
free(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for getOffset() and setOffset()
|
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestOffset()
|
2001-04-18 19:31:05 +00:00
|
|
|
{
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status= U_ZERO_ERROR;
|
2001-02-28 22:23:00 +00:00
|
|
|
UCollator *en_us=NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
UCollationElements *iter, *pristine;
|
|
|
|
int32_t offset;
|
2008-05-23 04:22:28 +00:00
|
|
|
OrderAndOffset *orders;
|
1999-08-16 21:50:52 +00:00
|
|
|
int32_t orderLength=0;
|
2001-06-26 23:02:07 +00:00
|
|
|
int count = 0;
|
2008-02-16 01:31:32 +00:00
|
|
|
UChar test1[50];
|
|
|
|
UChar test2[50];
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
u_uastrcpy(test1, "What subset of all possible test cases?");
|
|
|
|
u_uastrcpy(test2, "has the highest probability of detecting");
|
|
|
|
en_us = ucol_open("en_US", &status);
|
2003-11-11 21:41:47 +00:00
|
|
|
log_verbose("Testing getOffset and setOffset for collations\n");
|
2001-06-26 23:02:07 +00:00
|
|
|
iter = ucol_openElements(en_us, test1, u_strlen(test1), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
2001-06-26 23:02:07 +00:00
|
|
|
ucol_close(en_us);
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-07-09 23:16:04 +00:00
|
|
|
|
|
|
|
/* testing boundaries */
|
|
|
|
ucol_setOffset(iter, 0, &status);
|
|
|
|
if (U_FAILURE(status) || ucol_previous(iter, &status) != UCOL_NULLORDER) {
|
|
|
|
log_err("Error: After setting offset to 0, we should be at the end "
|
|
|
|
"of the backwards iteration");
|
|
|
|
}
|
|
|
|
ucol_setOffset(iter, u_strlen(test1), &status);
|
|
|
|
if (U_FAILURE(status) || ucol_next(iter, &status) != UCOL_NULLORDER) {
|
|
|
|
log_err("Error: After setting offset to end of the string, we should "
|
|
|
|
"be at the end of the backwards iteration");
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Run all the way through the iterator, then get the offset */
|
|
|
|
|
|
|
|
orders = getOrders(iter, &orderLength);
|
|
|
|
|
|
|
|
offset = ucol_getOffset(iter);
|
|
|
|
|
|
|
|
if (offset != u_strlen(test1))
|
|
|
|
{
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("offset at end != length %d vs %d\n", offset,
|
1999-08-16 21:50:52 +00:00
|
|
|
u_strlen(test1) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now set the offset back to the beginning and see if it works */
|
|
|
|
pristine=ucol_openElements(en_us, test1, u_strlen(test1), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
2001-02-28 22:23:00 +00:00
|
|
|
ucol_close(en_us);
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
1999-10-07 00:07:53 +00:00
|
|
|
status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
ucol_setOffset(iter, 0, &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("setOffset failed. %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assertEqual(iter, pristine);
|
|
|
|
}
|
2000-08-28 21:43:03 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_closeElements(pristine);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
free(orders);
|
2001-06-26 23:02:07 +00:00
|
|
|
|
|
|
|
/* testing offsets in normalization buffer */
|
|
|
|
test1[0] = 0x61;
|
|
|
|
test1[1] = 0x300;
|
|
|
|
test1[2] = 0x316;
|
|
|
|
test1[3] = 0x62;
|
|
|
|
test1[4] = 0;
|
|
|
|
ucol_setAttribute(en_us, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
|
|
|
|
iter = ucol_openElements(en_us, test1, 4, &status);
|
|
|
|
if(U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in creation of collation element iterator using ucol_openElements()\n %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
ucol_close(en_us);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
while (ucol_next(iter, &status) != UCOL_NULLORDER &&
|
|
|
|
U_SUCCESS(status)) {
|
|
|
|
switch (count) {
|
|
|
|
case 0:
|
|
|
|
if (ucol_getOffset(iter) != 1) {
|
2008-05-23 04:22:28 +00:00
|
|
|
log_err("ERROR: Offset of iteration should be 1\n");
|
2001-06-26 23:02:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if (ucol_getOffset(iter) != 4) {
|
|
|
|
log_err("ERROR: Offset of iteration should be 4\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (ucol_getOffset(iter) != 3) {
|
|
|
|
log_err("ERROR: Offset of iteration should be 3\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ucol_reset(iter);
|
|
|
|
count = 0;
|
|
|
|
while (ucol_previous(iter, &status) != UCOL_NULLORDER &&
|
|
|
|
U_SUCCESS(status)) {
|
|
|
|
switch (count) {
|
|
|
|
case 0:
|
2008-05-23 04:22:28 +00:00
|
|
|
case 1:
|
2001-06-26 23:02:07 +00:00
|
|
|
if (ucol_getOffset(iter) != 3) {
|
|
|
|
log_err("ERROR: Offset of iteration should be 3\n");
|
|
|
|
}
|
|
|
|
break;
|
2008-05-23 04:22:28 +00:00
|
|
|
case 2:
|
|
|
|
if (ucol_getOffset(iter) != 1) {
|
|
|
|
log_err("ERROR: Offset of iteration should be 1\n");
|
|
|
|
}
|
|
|
|
break;
|
2001-06-26 23:02:07 +00:00
|
|
|
default:
|
|
|
|
if (ucol_getOffset(iter) != 0) {
|
|
|
|
log_err("ERROR: Offset of iteration should be 0\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
count ++;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-06-26 23:02:07 +00:00
|
|
|
if(U_FAILURE(status)){
|
|
|
|
log_err("ERROR: in iterating collation elements %s\n",
|
|
|
|
myErrorName(status));
|
|
|
|
}
|
|
|
|
|
|
|
|
ucol_closeElements(iter);
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_close(en_us);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for setText()
|
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestSetText()
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t c,i;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-02-28 22:23:00 +00:00
|
|
|
UCollator *en_us=NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
UCollationElements *iter1, *iter2;
|
2008-02-16 01:31:32 +00:00
|
|
|
UChar test1[50];
|
|
|
|
UChar test2[50];
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
u_uastrcpy(test1, "What subset of all possible test cases?");
|
|
|
|
u_uastrcpy(test2, "has the highest probability of detecting");
|
|
|
|
en_us = ucol_open("en_US", &status);
|
|
|
|
log_verbose("testing setText for Collation elements\n");
|
|
|
|
iter1=ucol_openElements(en_us, test1, u_strlen(test1), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator1 using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
2001-02-28 22:23:00 +00:00
|
|
|
ucol_close(en_us);
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
iter2=ucol_openElements(en_us, test2, u_strlen(test2), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if(U_FAILURE(status)){
|
2001-04-18 19:31:05 +00:00
|
|
|
log_err("ERROR: in creation of collation element iterator2 using ucol_openElements()\n %s\n",
|
1999-08-16 21:50:52 +00:00
|
|
|
myErrorName(status));
|
2001-02-28 22:23:00 +00:00
|
|
|
ucol_close(en_us);
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
/* Run through the second iterator just to exercise it */
|
|
|
|
c = ucol_next(iter2, &status);
|
|
|
|
i = 0;
|
|
|
|
|
2001-02-23 23:41:16 +00:00
|
|
|
while ( ++i < 10 && (c != UCOL_NULLORDER))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("iter2->next() returned an error. %s\n", myErrorName(status));
|
|
|
|
ucol_closeElements(iter2);
|
|
|
|
ucol_closeElements(iter1);
|
2001-02-28 22:23:00 +00:00
|
|
|
ucol_close(en_us);
|
1999-08-16 21:50:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = ucol_next(iter2, &status);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now set it to point to the same string as the first iterator */
|
|
|
|
ucol_setText(iter2, test1, u_strlen(test1), &status);
|
1999-10-18 22:48:32 +00:00
|
|
|
if (U_FAILURE(status))
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
log_err("call to iter2->setText(test1) failed. %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assertEqual(iter1, iter2);
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-06-26 17:44:23 +00:00
|
|
|
/* Now set it to point to a null string with fake length*/
|
|
|
|
ucol_setText(iter2, NULL, 2, &status);
|
|
|
|
if (U_FAILURE(status))
|
|
|
|
{
|
|
|
|
log_err("call to iter2->setText(null) failed. %s\n", myErrorName(status));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ucol_next(iter2, &status) != UCOL_NULLORDER) {
|
|
|
|
log_err("iter2 with null text expected to return UCOL_NULLORDER\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
ucol_closeElements(iter2);
|
|
|
|
ucol_closeElements(iter1);
|
2000-11-21 04:05:39 +00:00
|
|
|
ucol_close(en_us);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 19:04:32 +00:00
|
|
|
/** @bug 4108762
|
|
|
|
* Test for getMaxExpansion()
|
|
|
|
*/
|
2000-11-21 04:05:39 +00:00
|
|
|
static void TestMaxExpansion()
|
2000-06-22 19:04:32 +00:00
|
|
|
{
|
2001-04-18 19:31:05 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-03-27 00:34:10 +00:00
|
|
|
UCollator *coll ;/*= ucol_open("en_US", &status);*/
|
|
|
|
UChar ch = 0;
|
2003-08-23 01:46:02 +00:00
|
|
|
UChar32 unassigned = 0xEFFFD;
|
|
|
|
UChar supplementary[2];
|
|
|
|
uint32_t index = 0;
|
|
|
|
UBool isError = FALSE;
|
2001-06-12 15:54:05 +00:00
|
|
|
uint32_t sorder = 0;
|
2001-03-27 00:34:10 +00:00
|
|
|
UCollationElements *iter ;/*= ucol_openElements(coll, &ch, 1, &status);*/
|
2001-06-12 15:54:05 +00:00
|
|
|
uint32_t temporder = 0;
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-03-27 00:34:10 +00:00
|
|
|
UChar rule[256];
|
|
|
|
u_uastrcpy(rule, "&a < ab < c/aba < d < z < ch");
|
2001-09-22 01:17:26 +00:00
|
|
|
coll = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT,
|
2001-08-16 00:58:53 +00:00
|
|
|
UCOL_DEFAULT_STRENGTH,NULL, &status);
|
2003-06-04 06:53:23 +00:00
|
|
|
if(U_SUCCESS(status) && coll) {
|
|
|
|
iter = ucol_openElements(coll, &ch, 1, &status);
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
while (ch < 0xFFFF && U_SUCCESS(status)) {
|
|
|
|
int count = 1;
|
|
|
|
uint32_t order;
|
|
|
|
int32_t size = 0;
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ch ++;
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ucol_setText(iter, &ch, 1, &status);
|
|
|
|
order = ucol_previous(iter, &status);
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
/* thai management */
|
|
|
|
if (order == 0)
|
|
|
|
order = ucol_previous(iter, &status);
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
while (U_SUCCESS(status) &&
|
|
|
|
ucol_previous(iter, &status) != UCOL_NULLORDER) {
|
|
|
|
count ++;
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
size = ucol_getMaxExpansion(iter, order);
|
|
|
|
if (U_FAILURE(status) || size < count) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count < %d\n",
|
|
|
|
ch, count);
|
|
|
|
}
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
/* testing for exact max expansion */
|
|
|
|
ch = 0;
|
|
|
|
while (ch < 0x61) {
|
|
|
|
uint32_t order;
|
|
|
|
int32_t size;
|
|
|
|
ucol_setText(iter, &ch, 1, &status);
|
|
|
|
order = ucol_previous(iter, &status);
|
|
|
|
size = ucol_getMaxExpansion(iter, order);
|
|
|
|
if (U_FAILURE(status) || size != 1) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count < %d\n",
|
|
|
|
ch, 1);
|
|
|
|
}
|
|
|
|
ch ++;
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ch = 0x63;
|
|
|
|
ucol_setText(iter, &ch, 1, &status);
|
|
|
|
temporder = ucol_previous(iter, &status);
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) != 3) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count != %d\n",
|
|
|
|
ch, 3);
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ch = 0x64;
|
|
|
|
ucol_setText(iter, &ch, 1, &status);
|
|
|
|
temporder = ucol_previous(iter, &status);
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) != 1) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count != %d\n",
|
|
|
|
ch, 3);
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-08-23 01:46:02 +00:00
|
|
|
U16_APPEND(supplementary, index, 2, unassigned, isError);
|
2003-06-04 06:53:23 +00:00
|
|
|
ucol_setText(iter, supplementary, 2, &status);
|
|
|
|
sorder = ucol_previous(iter, &status);
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
if (U_FAILURE(status) || ucol_getMaxExpansion(iter, sorder) != 2) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count < %d\n",
|
|
|
|
ch, 2);
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
/* testing jamo */
|
|
|
|
ch = 0x1165;
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ucol_setText(iter, &ch, 1, &status);
|
|
|
|
temporder = ucol_previous(iter, &status);
|
|
|
|
if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) > 3) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count > %d\n",
|
|
|
|
ch, 3);
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
|
|
|
|
/* testing special jamo &a<\u1160 */
|
|
|
|
rule[0] = 0x26;
|
|
|
|
rule[1] = 0x71;
|
|
|
|
rule[2] = 0x3c;
|
|
|
|
rule[3] = 0x1165;
|
|
|
|
rule[4] = 0x2f;
|
|
|
|
rule[5] = 0x71;
|
|
|
|
rule[6] = 0x71;
|
|
|
|
rule[7] = 0x71;
|
|
|
|
rule[8] = 0x71;
|
|
|
|
rule[9] = 0;
|
|
|
|
|
|
|
|
coll = ucol_openRules(rule, u_strlen(rule), UCOL_DEFAULT,
|
|
|
|
UCOL_DEFAULT_STRENGTH,NULL, &status);
|
|
|
|
iter = ucol_openElements(coll, &ch, 1, &status);
|
|
|
|
|
|
|
|
temporder = ucol_previous(iter, &status);
|
|
|
|
if (U_FAILURE(status) || ucol_getMaxExpansion(iter, temporder) != 6) {
|
|
|
|
log_err("Failure at codepoint %d, maximum expansion count > %d\n",
|
|
|
|
ch, 5);
|
|
|
|
}
|
2001-06-12 15:54:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
} else {
|
|
|
|
log_data_err("Couldn't open collator\n");
|
2001-06-12 15:54:05 +00:00
|
|
|
}
|
|
|
|
|
2000-06-22 19:04:32 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2000-11-21 04:05:39 +00:00
|
|
|
static void assertEqual(UCollationElements *i1, UCollationElements *i2)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
|
|
|
int32_t c1, c2;
|
|
|
|
int32_t count = 0;
|
1999-10-07 00:07:53 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c1 = ucol_next(i1, &status);
|
|
|
|
c2 = ucol_next(i2, &status);
|
2000-08-28 21:43:03 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
if (c1 != c2)
|
|
|
|
{
|
|
|
|
log_err("Error in iteration %d assetEqual between\n %d and %d, they are not equal\n", count, c1, c2);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
while (c1 != UCOL_NULLORDER);
|
|
|
|
}
|
|
|
|
|
2001-04-18 19:31:05 +00:00
|
|
|
/**
|
2001-04-17 17:27:37 +00:00
|
|
|
* Testing iterators with extremely small buffers
|
|
|
|
*/
|
|
|
|
static void TestSmallBuffer()
|
|
|
|
{
|
2001-04-18 19:31:05 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-04-17 17:27:37 +00:00
|
|
|
UCollator *coll;
|
2001-04-19 21:49:37 +00:00
|
|
|
UCollationElements *testiter,
|
|
|
|
*iter;
|
2001-04-25 21:11:53 +00:00
|
|
|
int32_t count = 0;
|
2008-05-23 04:22:28 +00:00
|
|
|
OrderAndOffset *testorders,
|
2001-04-19 21:49:37 +00:00
|
|
|
*orders;
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2001-04-19 21:49:37 +00:00
|
|
|
UChar teststr[500];
|
|
|
|
UChar str[] = {0x300, 0x31A, 0};
|
2001-04-18 19:31:05 +00:00
|
|
|
/*
|
2001-04-17 17:27:37 +00:00
|
|
|
creating a long string of decomposable characters,
|
|
|
|
since by default the writable buffer is of size 256
|
|
|
|
*/
|
|
|
|
while (count < 500) {
|
|
|
|
if ((count & 1) == 0) {
|
2001-04-19 21:49:37 +00:00
|
|
|
teststr[count ++] = 0x300;
|
2001-04-17 17:27:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-04-19 21:49:37 +00:00
|
|
|
teststr[count ++] = 0x31A;
|
2001-04-17 17:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
coll = ucol_open("th_TH", &status);
|
2003-06-04 06:53:23 +00:00
|
|
|
if(U_SUCCESS(status) && coll) {
|
|
|
|
testiter = ucol_openElements(coll, teststr, 500, &status);
|
|
|
|
iter = ucol_openElements(coll, str, 2, &status);
|
2001-04-19 21:49:37 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
orders = getOrders(iter, &count);
|
|
|
|
if (count != 2) {
|
|
|
|
log_err("Error collation elements size is not 2 for \\u0300\\u031A\n");
|
|
|
|
}
|
2001-04-17 17:27:37 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
/*
|
|
|
|
this will rearrange the string data to 250 characters of 0x300 first then
|
|
|
|
250 characters of 0x031A
|
|
|
|
*/
|
|
|
|
testorders = getOrders(testiter, &count);
|
2001-04-17 17:27:37 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
if (count != 500) {
|
|
|
|
log_err("Error decomposition does not give the right sized collation elements\n");
|
|
|
|
}
|
2001-03-09 18:16:37 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
while (count != 0) {
|
|
|
|
/* UCA collation element for 0x0F76 */
|
2008-05-23 04:22:28 +00:00
|
|
|
if ((count > 250 && testorders[-- count].order != orders[1].order) ||
|
|
|
|
(count <= 250 && testorders[-- count].order != orders[0].order)) {
|
2003-06-04 06:53:23 +00:00
|
|
|
log_err("Error decomposition does not give the right collation element at %d count\n", count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2001-04-18 19:31:05 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
free(testorders);
|
|
|
|
free(orders);
|
2001-06-28 20:44:09 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
ucol_reset(testiter);
|
|
|
|
/* ensures that the writable buffer was cleared */
|
|
|
|
if (testiter->iteratordata_.writableBuffer !=
|
|
|
|
testiter->iteratordata_.stackWritableBuffer) {
|
|
|
|
log_err("Error Writable buffer in collation element iterator not reset\n");
|
|
|
|
}
|
2001-06-28 20:44:09 +00:00
|
|
|
|
2003-06-04 06:53:23 +00:00
|
|
|
/* ensures closing of elements done properly to clear writable buffer */
|
|
|
|
ucol_next(testiter, &status);
|
|
|
|
ucol_next(testiter, &status);
|
|
|
|
ucol_closeElements(testiter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
} else {
|
|
|
|
log_data_err("Couldn't open collator\n");
|
|
|
|
}
|
2001-04-17 17:27:37 +00:00
|
|
|
}
|
2001-05-14 18:58:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sniplets of code from genuca
|
|
|
|
*/
|
|
|
|
static int32_t hex2num(char hex) {
|
|
|
|
if(hex>='0' && hex <='9') {
|
|
|
|
return hex-'0';
|
|
|
|
} else if(hex>='a' && hex<='f') {
|
|
|
|
return hex-'a'+10;
|
|
|
|
} else if(hex>='A' && hex<='F') {
|
|
|
|
return hex-'A'+10;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
/**
|
|
|
|
* Getting codepoints from a string
|
|
|
|
* @param str character string contain codepoints seperated by space and ended
|
2001-05-14 18:58:36 +00:00
|
|
|
* by a semicolon
|
|
|
|
* @param codepoints array for storage, assuming size > 5
|
|
|
|
* @return position at the end of the codepoint section
|
|
|
|
*/
|
2008-04-04 22:47:43 +00:00
|
|
|
static char * getCodePoints(char *str, UChar *codepoints, UChar *contextCPs) {
|
2001-05-14 18:58:36 +00:00
|
|
|
char *pStartCP = str;
|
|
|
|
char *pEndCP = str + 4;
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
*codepoints = (UChar)((hex2num(*pStartCP) << 12) |
|
|
|
|
(hex2num(*(pStartCP + 1)) << 8) |
|
|
|
|
(hex2num(*(pStartCP + 2)) << 4) |
|
2001-05-14 18:58:36 +00:00
|
|
|
(hex2num(*(pStartCP + 3))));
|
2008-04-04 22:47:43 +00:00
|
|
|
if (*pEndCP == '|' || *(pEndCP+1) == '|') {
|
|
|
|
/* pre-context rule */
|
|
|
|
pStartCP = pEndCP;
|
|
|
|
while (*pStartCP==' ' || *pStartCP== '|' ) {
|
|
|
|
pStartCP++;
|
|
|
|
}
|
|
|
|
pEndCP = pStartCP+4;
|
|
|
|
*contextCPs = *codepoints;
|
|
|
|
*(++codepoints) = (UChar)((hex2num(*pStartCP) << 12) |
|
|
|
|
(hex2num(*(pStartCP + 1)) << 8) |
|
|
|
|
(hex2num(*(pStartCP + 2)) << 4) |
|
|
|
|
(hex2num(*(pStartCP + 3))));
|
|
|
|
contextCPs++;
|
|
|
|
}
|
|
|
|
*contextCPs = 0;
|
2001-05-14 18:58:36 +00:00
|
|
|
codepoints ++;
|
|
|
|
while (*pEndCP != ';') {
|
|
|
|
pStartCP = pEndCP + 1;
|
2001-11-02 02:24:15 +00:00
|
|
|
*codepoints = (UChar)((hex2num(*pStartCP) << 12) |
|
|
|
|
(hex2num(*(pStartCP + 1)) << 8) |
|
|
|
|
(hex2num(*(pStartCP + 2)) << 4) |
|
2001-05-14 18:58:36 +00:00
|
|
|
(hex2num(*(pStartCP + 3))));
|
|
|
|
codepoints ++;
|
|
|
|
pEndCP = pStartCP + 4;
|
|
|
|
}
|
|
|
|
*codepoints = 0;
|
|
|
|
return pEndCP + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sniplets of code from genuca
|
|
|
|
*/
|
2001-05-21 23:41:44 +00:00
|
|
|
static int32_t
|
|
|
|
readElement(char **from, char *to, char separator, UErrorCode *status)
|
|
|
|
{
|
2001-05-14 18:58:36 +00:00
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
char buffer[1024];
|
|
|
|
int32_t i = 0;
|
|
|
|
while (**from != separator) {
|
|
|
|
if (**from != ' ') {
|
|
|
|
*(buffer+i++) = **from;
|
|
|
|
}
|
|
|
|
(*from)++;
|
|
|
|
}
|
|
|
|
(*from)++;
|
|
|
|
*(buffer + i) = 0;
|
|
|
|
strcpy(to, buffer);
|
2001-11-02 02:24:15 +00:00
|
|
|
return i/2;
|
2001-05-14 18:58:36 +00:00
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-14 18:58:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sniplets of code from genuca
|
|
|
|
*/
|
2001-05-21 23:41:44 +00:00
|
|
|
static uint32_t
|
2001-11-02 02:24:15 +00:00
|
|
|
getSingleCEValue(char *primary, char *secondary, char *tertiary,
|
2001-05-21 23:41:44 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-05-14 18:58:36 +00:00
|
|
|
if (U_SUCCESS(*status)) {
|
|
|
|
uint32_t value = 0;
|
|
|
|
char primsave = '\0';
|
|
|
|
char secsave = '\0';
|
|
|
|
char tersave = '\0';
|
|
|
|
char *primend = primary+4;
|
|
|
|
char *secend = secondary+2;
|
|
|
|
char *terend = tertiary+2;
|
|
|
|
uint32_t primvalue;
|
|
|
|
uint32_t secvalue;
|
|
|
|
uint32_t tervalue;
|
|
|
|
|
2001-05-21 23:41:44 +00:00
|
|
|
if (uprv_strlen(primary) > 4) {
|
2001-05-14 18:58:36 +00:00
|
|
|
primsave = *primend;
|
|
|
|
*primend = '\0';
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-21 23:41:44 +00:00
|
|
|
if (uprv_strlen(secondary) > 2) {
|
2001-05-14 18:58:36 +00:00
|
|
|
secsave = *secend;
|
|
|
|
*secend = '\0';
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-21 23:41:44 +00:00
|
|
|
if (uprv_strlen(tertiary) > 2) {
|
2001-05-14 18:58:36 +00:00
|
|
|
tersave = *terend;
|
|
|
|
*terend = '\0';
|
|
|
|
}
|
|
|
|
|
2002-07-29 21:04:18 +00:00
|
|
|
primvalue = (*primary!='\0')?uprv_strtoul(primary, &primend, 16):0;
|
|
|
|
secvalue = (*secondary!='\0')?uprv_strtoul(secondary, &secend, 16):0;
|
|
|
|
tervalue = (*tertiary!='\0')?uprv_strtoul(tertiary, &terend, 16):0;
|
2001-05-14 18:58:36 +00:00
|
|
|
if(primvalue <= 0xFF) {
|
|
|
|
primvalue <<= 8;
|
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
value = ((primvalue << UCOL_PRIMARYORDERSHIFT) & UCOL_PRIMARYORDERMASK)
|
|
|
|
| ((secvalue << UCOL_SECONDARYORDERSHIFT) & UCOL_SECONDARYORDERMASK)
|
2001-05-14 18:58:36 +00:00
|
|
|
| (tervalue & UCOL_TERTIARYORDERMASK);
|
|
|
|
|
|
|
|
if(primsave!='\0') {
|
|
|
|
*primend = primsave;
|
|
|
|
}
|
|
|
|
if(secsave!='\0') {
|
|
|
|
*secend = secsave;
|
|
|
|
}
|
|
|
|
if(tersave!='\0') {
|
|
|
|
*terend = tersave;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
/**
|
|
|
|
* Getting collation elements generated from a string
|
|
|
|
* @param str character string contain collation elements contained in [] and
|
2001-05-14 18:58:36 +00:00
|
|
|
* seperated by space
|
|
|
|
* @param ce array for storage, assuming size > 20
|
|
|
|
* @param status error status
|
|
|
|
* @return position at the end of the codepoint section
|
|
|
|
*/
|
|
|
|
static char * getCEs(char *str, uint32_t *ces, UErrorCode *status) {
|
|
|
|
char *pStartCP = uprv_strchr(str, '[');
|
|
|
|
int count = 0;
|
|
|
|
char *pEndCP;
|
|
|
|
char primary[100];
|
|
|
|
char secondary[100];
|
|
|
|
char tertiary[100];
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-14 18:58:36 +00:00
|
|
|
while (*pStartCP == '[') {
|
|
|
|
uint32_t primarycount = 0;
|
|
|
|
uint32_t secondarycount = 0;
|
|
|
|
uint32_t tertiarycount = 0;
|
|
|
|
uint32_t CEi = 1;
|
|
|
|
pEndCP = strchr(pStartCP, ']');
|
|
|
|
if(pEndCP == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pStartCP ++;
|
|
|
|
|
|
|
|
primarycount = readElement(&pStartCP, primary, ',', status);
|
|
|
|
secondarycount = readElement(&pStartCP, secondary, ',', status);
|
|
|
|
tertiarycount = readElement(&pStartCP, tertiary, ']', status);
|
|
|
|
|
|
|
|
/* I want to get the CEs entered right here, including continuation */
|
|
|
|
ces[count ++] = getSingleCEValue(primary, secondary, tertiary, status);
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
while (2 * CEi < primarycount || CEi < secondarycount ||
|
2001-05-14 18:58:36 +00:00
|
|
|
CEi < tertiarycount) {
|
|
|
|
uint32_t value = UCOL_CONTINUATION_MARKER; /* Continuation marker */
|
|
|
|
if (2 * CEi < primarycount) {
|
|
|
|
value |= ((hex2num(*(primary + 4 * CEi)) & 0xF) << 28);
|
|
|
|
value |= ((hex2num(*(primary + 4 * CEi + 1)) & 0xF) << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (2 * CEi + 1 < primarycount) {
|
|
|
|
value |= ((hex2num(*(primary + 4 * CEi + 2)) & 0xF) << 20);
|
|
|
|
value |= ((hex2num(*(primary + 4 * CEi + 3)) &0xF) << 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CEi < secondarycount) {
|
|
|
|
value |= ((hex2num(*(secondary + 2 * CEi)) & 0xF) << 12);
|
|
|
|
value |= ((hex2num(*(secondary + 2 * CEi + 1)) & 0xF) << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CEi < tertiarycount) {
|
|
|
|
value |= ((hex2num(*(tertiary + 2 * CEi)) & 0x3) << 4);
|
|
|
|
value |= (hex2num(*(tertiary + 2 * CEi + 1)) & 0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEi ++;
|
|
|
|
ces[count ++] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
pStartCP = pEndCP + 1;
|
|
|
|
}
|
|
|
|
ces[count] = 0;
|
|
|
|
return pStartCP;
|
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
/**
|
2001-05-25 16:54:33 +00:00
|
|
|
* Getting the FractionalUCA.txt file stream
|
|
|
|
*/
|
2001-05-30 17:38:28 +00:00
|
|
|
static FileStream * getFractionalUCA(void)
|
2001-05-25 16:54:33 +00:00
|
|
|
{
|
2001-05-30 22:07:12 +00:00
|
|
|
char newPath[256];
|
|
|
|
char backupPath[256];
|
|
|
|
FileStream *result = NULL;
|
|
|
|
|
|
|
|
/* Look inside ICU_DATA first */
|
2004-09-23 00:24:36 +00:00
|
|
|
uprv_strcpy(newPath, ctest_dataSrcDir());
|
2001-05-30 22:07:12 +00:00
|
|
|
uprv_strcat(newPath, "unidata" U_FILE_SEP_STRING );
|
|
|
|
uprv_strcat(newPath, "FractionalUCA.txt");
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
/* As a fallback, try to guess where the source data was located
|
|
|
|
* at the time ICU was built, and look there.
|
|
|
|
*/
|
2002-04-25 21:38:10 +00:00
|
|
|
#if defined (U_TOPSRCDIR)
|
|
|
|
strcpy(backupPath, U_TOPSRCDIR U_FILE_SEP_STRING "data");
|
|
|
|
#else
|
|
|
|
{
|
|
|
|
UErrorCode errorCode = U_ZERO_ERROR;
|
|
|
|
strcpy(backupPath, loadTestData(&errorCode));
|
|
|
|
strcat(backupPath, U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING ".." U_FILE_SEP_STRING "data");
|
|
|
|
}
|
|
|
|
#endif
|
2001-11-02 02:24:15 +00:00
|
|
|
strcat(backupPath, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "FractionalUCA.txt");
|
|
|
|
|
2001-05-30 22:07:12 +00:00
|
|
|
result = T_FileStream_open(newPath, "rb");
|
|
|
|
|
|
|
|
if (result == NULL) {
|
|
|
|
result = T_FileStream_open(backupPath, "rb");
|
|
|
|
if (result == NULL) {
|
|
|
|
log_err("Failed to open either %s or %s\n", newPath, backupPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
|
|
|
|
2001-05-14 18:58:36 +00:00
|
|
|
/**
|
|
|
|
* Testing the CEs returned by the iterator
|
|
|
|
*/
|
|
|
|
static void TestCEs() {
|
|
|
|
FileStream *file = NULL;
|
2002-06-13 18:35:27 +00:00
|
|
|
char line[1024];
|
2001-05-14 18:58:36 +00:00
|
|
|
char *str;
|
2008-04-04 22:47:43 +00:00
|
|
|
UChar codepoints[10];
|
2001-05-14 18:58:36 +00:00
|
|
|
uint32_t ces[20];
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UCollator *coll = ucol_open("", &status);
|
2002-06-13 18:35:27 +00:00
|
|
|
uint32_t lineNo = 0;
|
2008-04-04 22:47:43 +00:00
|
|
|
UChar contextCPs[5];
|
2001-05-14 18:58:36 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error in opening root collator\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
file = getFractionalUCA();
|
2001-05-14 18:58:36 +00:00
|
|
|
|
|
|
|
if (file == NULL) {
|
|
|
|
log_err("*** unable to open input FractionalUCA.txt file ***\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-06-13 18:35:27 +00:00
|
|
|
|
2001-05-14 18:58:36 +00:00
|
|
|
while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) {
|
|
|
|
int count = 0;
|
|
|
|
UCollationElements *iter;
|
2008-04-04 22:47:43 +00:00
|
|
|
int32_t preContextCeLen=0;
|
2002-06-13 18:35:27 +00:00
|
|
|
lineNo++;
|
2001-11-02 02:24:15 +00:00
|
|
|
/* skip this line if it is empty or a comment or is a return value
|
2001-05-14 18:58:36 +00:00
|
|
|
or start of some variable section */
|
2001-11-02 02:24:15 +00:00
|
|
|
if(line[0] == 0 || line[0] == '#' || line[0] == '\n' ||
|
2001-05-30 22:07:12 +00:00
|
|
|
line[0] == 0x000D || line[0] == '[') {
|
2001-05-14 18:58:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-04-04 22:47:43 +00:00
|
|
|
str = getCodePoints(line, codepoints, contextCPs);
|
2002-06-13 18:35:27 +00:00
|
|
|
|
2002-07-02 22:36:04 +00:00
|
|
|
/* these are 'fake' codepoints in the fractional UCA, and are used just
|
|
|
|
* for positioning of indirect values. They should not go through this
|
|
|
|
* test.
|
|
|
|
*/
|
|
|
|
if(*codepoints == 0xFDD0) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-04 22:47:43 +00:00
|
|
|
if (*contextCPs != 0) {
|
|
|
|
iter = ucol_openElements(coll, contextCPs, -1, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error in opening collation elements\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
while((ces[preContextCeLen] = ucol_next(iter, &status)) != (uint32_t)UCOL_NULLORDER) {
|
|
|
|
preContextCeLen++;
|
|
|
|
}
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
}
|
2002-07-02 22:36:04 +00:00
|
|
|
|
2008-04-04 22:47:43 +00:00
|
|
|
getCEs(str, ces+preContextCeLen, &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error in parsing collation elements in FractionalUCA.txt\n");
|
|
|
|
break;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
iter = ucol_openElements(coll, codepoints, -1, &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error in opening collation elements\n");
|
|
|
|
break;
|
2001-11-02 02:24:15 +00:00
|
|
|
}
|
2001-05-21 23:41:44 +00:00
|
|
|
for (;;) {
|
2001-05-14 18:58:36 +00:00
|
|
|
uint32_t ce = (uint32_t)ucol_next(iter, &status);
|
|
|
|
if (ce == 0xFFFFFFFF) {
|
|
|
|
ce = 0;
|
|
|
|
}
|
2002-07-09 23:57:45 +00:00
|
|
|
/* we now unconditionally reorder Thai/Lao prevowels, so this
|
|
|
|
* test would fail if we don't skip here.
|
|
|
|
*/
|
|
|
|
if(UCOL_ISTHAIPREVOWEL(*codepoints) && ce == 0 && count == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2001-05-14 18:58:36 +00:00
|
|
|
if (ce != ces[count] || U_FAILURE(status)) {
|
|
|
|
log_err("Collation elements in FractionalUCA.txt and iterators do not match!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ces[count] == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
T_FileStream_close(file);
|
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Testing the discontigous contractions
|
|
|
|
*/
|
|
|
|
static void TestDiscontiguos() {
|
2001-11-02 02:24:15 +00:00
|
|
|
const char *rulestr =
|
2001-05-14 18:58:36 +00:00
|
|
|
"&z < AB < X\\u0300 < ABC < X\\u0300\\u0315";
|
|
|
|
UChar rule[50];
|
|
|
|
int rulelen = u_unescape(rulestr, rule, 50);
|
|
|
|
const char *src[] = {
|
2001-11-02 02:24:15 +00:00
|
|
|
"ADB", "ADBC", "A\\u0315B", "A\\u0315BC",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* base character blocked */
|
2001-11-02 02:24:15 +00:00
|
|
|
"XD\\u0300", "XD\\u0300\\u0315",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* non blocking combining character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X\\u0319\\u0300", "X\\u0319\\u0300\\u0315",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* blocking combining character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X\\u0314\\u0300", "X\\u0314\\u0300\\u0315",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* contraction prefix */
|
|
|
|
"ABDC", "AB\\u0315C","X\\u0300D\\u0315", "X\\u0300\\u0319\\u0315",
|
2001-11-02 02:24:15 +00:00
|
|
|
"X\\u0300\\u031A\\u0315",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* ends not with a contraction character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X\\u0319\\u0300D", "X\\u0319\\u0300\\u0315D", "X\\u0300D\\u0315D",
|
2001-05-14 18:58:36 +00:00
|
|
|
"X\\u0300\\u0319\\u0315D", "X\\u0300\\u031A\\u0315D"
|
2001-11-02 02:24:15 +00:00
|
|
|
};
|
2001-05-14 18:58:36 +00:00
|
|
|
const char *tgt[] = {
|
|
|
|
/* non blocking combining character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"A D B", "A D BC", "A \\u0315 B", "A \\u0315 BC",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* base character blocked */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X D \\u0300", "X D \\u0300\\u0315",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* non blocking combining character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X\\u0300 \\u0319", "X\\u0300\\u0315 \\u0319",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* blocking combining character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X \\u0314 \\u0300", "X \\u0314 \\u0300\\u0315",
|
2001-05-14 18:58:36 +00:00
|
|
|
/* contraction prefix */
|
|
|
|
"AB DC", "AB \\u0315 C","X\\u0300 D \\u0315", "X\\u0300\\u0315 \\u0319",
|
|
|
|
"X\\u0300 \\u031A \\u0315",
|
|
|
|
/* ends not with a contraction character */
|
2001-11-02 02:24:15 +00:00
|
|
|
"X\\u0300 \\u0319D", "X\\u0300\\u0315 \\u0319D", "X\\u0300 D\\u0315D",
|
2001-05-14 18:58:36 +00:00
|
|
|
"X\\u0300\\u0315 \\u0319D", "X\\u0300 \\u031A\\u0315D"
|
|
|
|
};
|
|
|
|
int size = 20;
|
|
|
|
UCollator *coll;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
int count = 0;
|
2001-11-02 02:24:15 +00:00
|
|
|
UCollationElements *iter;
|
|
|
|
UCollationElements *resultiter;
|
|
|
|
|
2001-09-22 01:17:26 +00:00
|
|
|
coll = ucol_openRules(rule, rulelen, UCOL_OFF, UCOL_DEFAULT_STRENGTH,NULL, &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
iter = ucol_openElements(coll, rule, 1, &status);
|
|
|
|
resultiter = ucol_openElements(coll, rule, 1, &status);
|
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error opening collation rules\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (count < size) {
|
|
|
|
UChar str[20];
|
|
|
|
UChar tstr[20];
|
2001-05-21 23:41:44 +00:00
|
|
|
int strLen = u_unescape(src[count], str, 20);
|
2001-05-14 18:58:36 +00:00
|
|
|
UChar *s;
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
ucol_setText(iter, str, strLen, &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error opening collation iterator\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_unescape(tgt[count], tstr, 20);
|
|
|
|
s = tstr;
|
2001-05-17 01:07:10 +00:00
|
|
|
|
|
|
|
log_verbose("count %d\n", count);
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-21 23:41:44 +00:00
|
|
|
for (;;) {
|
2001-05-14 18:58:36 +00:00
|
|
|
uint32_t ce;
|
2001-05-31 16:30:03 +00:00
|
|
|
UChar *e = u_strchr(s, 0x20);
|
2001-05-14 18:58:36 +00:00
|
|
|
if (e == 0) {
|
|
|
|
e = u_strchr(s, 0);
|
|
|
|
}
|
2002-05-24 17:22:53 +00:00
|
|
|
ucol_setText(resultiter, s, (int32_t)(e - s), &status);
|
2001-05-14 18:58:36 +00:00
|
|
|
ce = ucol_next(resultiter, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error manipulating collation iterator\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
while (ce != UCOL_NULLORDER) {
|
2001-11-02 02:24:15 +00:00
|
|
|
if (ce != (uint32_t)ucol_next(iter, &status) ||
|
2001-05-14 18:58:36 +00:00
|
|
|
U_FAILURE(status)) {
|
|
|
|
log_err("Discontiguos contraction test mismatch\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ce = ucol_next(resultiter, &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error getting next collation element\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = e + 1;
|
|
|
|
if (*e == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ucol_reset(iter);
|
|
|
|
backAndForth(iter);
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
ucol_closeElements(resultiter);
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
static void TestCEBufferOverflow()
|
2001-05-17 21:35:14 +00:00
|
|
|
{
|
|
|
|
UChar str[UCOL_EXPAND_CE_BUFFER_SIZE + 1];
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar rule[10];
|
|
|
|
UCollator *coll;
|
|
|
|
UCollationElements *iter;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-17 21:35:14 +00:00
|
|
|
u_uastrcpy(rule, "&z < AB");
|
2001-09-22 01:17:26 +00:00
|
|
|
coll = ucol_openRules(rule, u_strlen(rule), UCOL_OFF, UCOL_DEFAULT_STRENGTH, NULL,&status);
|
2001-05-17 21:35:14 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Rule based collator not created for testing ce buffer overflow\n");
|
2003-06-04 06:53:23 +00:00
|
|
|
return;
|
2001-05-17 21:35:14 +00:00
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-09-18 18:37:57 +00:00
|
|
|
/* 0xDCDC is a trail surrogate hence deemed unsafe by the heuristic
|
2001-05-17 21:35:14 +00:00
|
|
|
test. this will cause an overflow in getPrev */
|
2001-05-31 16:30:03 +00:00
|
|
|
str[0] = 0x0041; /* 'A' */
|
2001-09-18 18:37:57 +00:00
|
|
|
/*uprv_memset(str + 1, 0xE0, sizeof(UChar) * UCOL_EXPAND_CE_BUFFER_SIZE);*/
|
|
|
|
uprv_memset(str + 1, 0xDC, sizeof(UChar) * UCOL_EXPAND_CE_BUFFER_SIZE);
|
2001-05-31 16:30:03 +00:00
|
|
|
str[UCOL_EXPAND_CE_BUFFER_SIZE] = 0x0042; /* 'B' */
|
2001-11-02 02:24:15 +00:00
|
|
|
iter = ucol_openElements(coll, str, UCOL_EXPAND_CE_BUFFER_SIZE + 1,
|
2001-05-17 21:35:14 +00:00
|
|
|
&status);
|
2007-12-15 00:30:35 +00:00
|
|
|
if (ucol_previous(iter, &status) == UCOL_NULLORDER ||
|
|
|
|
status == U_BUFFER_OVERFLOW_ERROR) {
|
|
|
|
log_err("CE buffer should not overflow with long string of trail surrogates\n");
|
2001-05-17 21:35:14 +00:00
|
|
|
}
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
ucol_close(coll);
|
|
|
|
}
|
2001-05-25 16:54:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Byte bounds checks. Checks if each byte in data is between upper and lower
|
|
|
|
* inclusive.
|
|
|
|
*/
|
|
|
|
static UBool checkByteBounds(uint32_t data, char upper, char lower)
|
|
|
|
{
|
|
|
|
int count = 4;
|
|
|
|
while (count > 0) {
|
2001-05-30 16:15:33 +00:00
|
|
|
char b = (char)(data & 0xFF);
|
2001-05-25 16:54:33 +00:00
|
|
|
if (b > upper || b < lower) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
data = data >> 8;
|
|
|
|
count --;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines case of the string of codepoints.
|
|
|
|
* If it is a multiple codepoints it has to treated as a contraction.
|
|
|
|
*/
|
2001-05-30 16:15:33 +00:00
|
|
|
#if 0
|
|
|
|
static uint8_t getCase(const UChar *s, uint32_t len) {
|
|
|
|
UBool lower = FALSE;
|
|
|
|
UBool upper = FALSE;
|
|
|
|
UBool title = FALSE;
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UChar str[256];
|
2001-05-25 16:54:33 +00:00
|
|
|
const UChar *ps = s;
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
return UCOL_LOWER_CASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
UChar c = *ps ++;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
if (u_islower(c)) {
|
|
|
|
lower = TRUE;
|
|
|
|
}
|
|
|
|
if (u_isupper(c)) {
|
|
|
|
upper = TRUE;
|
|
|
|
}
|
|
|
|
if (u_istitle(c)) {
|
|
|
|
title = TRUE;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
len --;
|
|
|
|
}
|
|
|
|
if ((lower && !upper && !title) || (!lower && !upper && !title)){
|
|
|
|
return UCOL_LOWER_CASE;
|
|
|
|
}
|
|
|
|
if (upper && !lower && !title) {
|
|
|
|
return UCOL_UPPER_CASE;
|
|
|
|
}
|
|
|
|
/* mix of cases here */
|
2001-11-02 02:24:15 +00:00
|
|
|
/* len = unorm_normalize(s, len, UNORM_NFKD, 0, str, 256, &status);
|
2001-05-25 16:54:33 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error normalizing data string\n");
|
|
|
|
return UCOL_LOWER_CASE;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
if ((title && len >= 2) || (lower && upper)) {
|
|
|
|
return UCOL_MIXED_CASE;
|
|
|
|
}
|
|
|
|
if (u_isupper(s[0])) {
|
|
|
|
return UCOL_UPPER_CASE;
|
|
|
|
}
|
|
|
|
return UCOL_LOWER_CASE;
|
|
|
|
}
|
2001-05-30 16:15:33 +00:00
|
|
|
#endif
|
2001-05-25 16:54:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checking collation element validity given the boundary arguments.
|
|
|
|
*/
|
2001-11-02 02:24:15 +00:00
|
|
|
static UBool checkCEValidity(const UCollator *coll, const UChar *codepoints,
|
|
|
|
int length, uint32_t primarymax,
|
|
|
|
uint32_t secondarymax)
|
2001-05-25 16:54:33 +00:00
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
UCollationElements *iter = ucol_openElements(coll, codepoints, length,
|
|
|
|
&status);
|
|
|
|
uint32_t ce;
|
|
|
|
UBool first = TRUE;
|
2001-05-30 16:15:33 +00:00
|
|
|
/*
|
2001-05-25 16:54:33 +00:00
|
|
|
UBool upper = FALSE;
|
|
|
|
UBool lower = FALSE;
|
2001-05-30 16:15:33 +00:00
|
|
|
*/
|
2001-05-25 16:54:33 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("Error creating iterator for testing validity\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
ce = ucol_next(iter, &status);
|
|
|
|
|
|
|
|
while (ce != UCOL_NULLORDER) {
|
|
|
|
if (ce != 0) {
|
|
|
|
uint32_t primary = UCOL_PRIMARYORDER(ce);
|
|
|
|
uint32_t secondary = UCOL_SECONDARYORDER(ce);
|
|
|
|
uint32_t tertiary = UCOL_TERTIARYORDER(ce);
|
2001-05-30 16:15:33 +00:00
|
|
|
/* uint32_t scasebits = tertiary & 0xC0;*/
|
2001-11-02 02:24:15 +00:00
|
|
|
|
|
|
|
if ((tertiary == 0 && secondary != 0) ||
|
2001-05-25 16:54:33 +00:00
|
|
|
(tertiary < 0xC0 && secondary == 0 && primary != 0)) {
|
|
|
|
/* n-1th level is not zero when the nth level is
|
|
|
|
except for continuations, this is wrong */
|
|
|
|
log_err("Lower level weight not 0 when high level weight is 0\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* checks if any byte is illegal ie = 01 02 03. */
|
|
|
|
if (checkByteBounds(ce, 0x3, 0x1)) {
|
|
|
|
log_err("Byte range in CE lies in illegal bounds 0x1 - 0x3\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2004-01-27 22:16:55 +00:00
|
|
|
if ((primary != 0 && primary < primarymax)
|
|
|
|
|| ((primary & 0xFF) == 0xFF) || (((primary>>8) & 0xFF) == 0xFF)
|
|
|
|
|| ((primary & 0xFF) && ((primary & 0xFF) <= 0x03))
|
|
|
|
|| (((primary>>8) & 0xFF) && ((primary>>8) & 0xFF) <= 0x03)
|
|
|
|
|| (primary >= 0xFE00 && !isContinuation(ce))) {
|
2004-01-16 07:14:08 +00:00
|
|
|
log_err("UCA primary weight out of bounds: %04X for string starting with %04X\n",
|
|
|
|
primary, codepoints[0]);
|
2001-11-06 22:55:29 +00:00
|
|
|
goto fail;
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
|
|
|
/* case matching not done since data generated by ken */
|
|
|
|
if (first) {
|
|
|
|
if (secondary >= 6 && secondary <= secondarymax) {
|
|
|
|
log_err("Secondary weight out of range\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
first = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ce = ucol_next(iter, &status);
|
|
|
|
}
|
|
|
|
ucol_closeElements(iter);
|
|
|
|
return TRUE;
|
2001-11-02 02:24:15 +00:00
|
|
|
fail :
|
2001-05-25 16:54:33 +00:00
|
|
|
ucol_closeElements(iter);
|
2001-11-02 02:24:15 +00:00
|
|
|
return FALSE;
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void TestCEValidity()
|
|
|
|
{
|
|
|
|
/* testing UCA collation elements */
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
/* en_US has no tailorings */
|
2004-01-16 07:14:08 +00:00
|
|
|
UCollator *coll = ucol_open("root", &status);
|
2001-05-25 16:54:33 +00:00
|
|
|
/* tailored locales */
|
2004-01-16 07:14:08 +00:00
|
|
|
char locale[][11] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN", "zh__PINYIN"};
|
|
|
|
const char *loc;
|
2008-02-17 19:32:34 +00:00
|
|
|
FileStream *file = NULL;
|
2002-06-13 18:35:27 +00:00
|
|
|
char line[1024];
|
2002-07-15 22:53:25 +00:00
|
|
|
UChar codepoints[10];
|
2001-05-25 16:54:33 +00:00
|
|
|
int count = 0;
|
2004-01-16 07:14:08 +00:00
|
|
|
int maxCount = 0;
|
2008-04-04 22:47:43 +00:00
|
|
|
UChar contextCPs[3];
|
2001-08-16 00:58:53 +00:00
|
|
|
UParseError parseError;
|
2001-05-25 16:54:33 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("en_US collator creation failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log_verbose("Testing UCA elements\n");
|
2008-02-17 19:32:34 +00:00
|
|
|
file = getFractionalUCA();
|
2001-05-25 16:54:33 +00:00
|
|
|
if (file == NULL) {
|
|
|
|
log_err("Fractional UCA data can not be opened\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) {
|
2001-11-02 02:24:15 +00:00
|
|
|
if(line[0] == 0 || line[0] == '#' || line[0] == '\n' ||
|
2001-05-30 22:07:12 +00:00
|
|
|
line[0] == 0x000D || line[0] == '[') {
|
2001-05-25 16:54:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-04-04 22:47:43 +00:00
|
|
|
getCodePoints(line, codepoints, contextCPs);
|
2001-05-25 16:54:33 +00:00
|
|
|
checkCEValidity(coll, codepoints, u_strlen(codepoints), 5, 86);
|
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("Testing UCA elements for the whole range of unicode characters\n");
|
|
|
|
codepoints[0] = 0;
|
|
|
|
while (codepoints[0] < 0xFFFF) {
|
|
|
|
if (u_isdefined((UChar32)codepoints[0])) {
|
|
|
|
checkCEValidity(coll, codepoints, 1, 5, 86);
|
|
|
|
}
|
|
|
|
codepoints[0] ++;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
ucol_close(coll);
|
|
|
|
|
|
|
|
/* testing tailored collation elements */
|
|
|
|
log_verbose("Testing tailored elements\n");
|
2004-01-16 07:14:08 +00:00
|
|
|
if(QUICK) {
|
|
|
|
maxCount = sizeof(locale)/sizeof(locale[0]);
|
|
|
|
} else {
|
|
|
|
maxCount = uloc_countAvailable();
|
|
|
|
}
|
|
|
|
while (count < maxCount) {
|
2001-11-02 02:24:15 +00:00
|
|
|
const UChar *rules = NULL,
|
2001-05-25 16:54:33 +00:00
|
|
|
*current = NULL;
|
|
|
|
UChar *rulesCopy = NULL;
|
|
|
|
int32_t ruleLen = 0;
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
uint32_t chOffset = 0;
|
2001-05-25 16:54:33 +00:00
|
|
|
uint32_t chLen = 0;
|
2001-11-02 02:24:15 +00:00
|
|
|
uint32_t exOffset = 0;
|
2001-05-25 16:54:33 +00:00
|
|
|
uint32_t exLen = 0;
|
2001-09-27 23:19:12 +00:00
|
|
|
uint32_t prefixOffset = 0;
|
|
|
|
uint32_t prefixLen = 0;
|
2001-05-25 16:54:33 +00:00
|
|
|
UBool startOfRules = TRUE;
|
|
|
|
UColOptionSet opts;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
UColTokenParser src;
|
|
|
|
uint32_t strength = 0;
|
2002-03-15 23:51:22 +00:00
|
|
|
uint16_t specs = 0;
|
2004-01-16 07:14:08 +00:00
|
|
|
if(QUICK) {
|
|
|
|
loc = locale[count];
|
|
|
|
} else {
|
|
|
|
loc = uloc_getAvailable(count);
|
|
|
|
if(!hasCollationElements(loc)) {
|
|
|
|
count++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("Testing CEs for %s\n", loc);
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2004-01-16 07:14:08 +00:00
|
|
|
coll = ucol_open(loc, &status);
|
2001-05-25 16:54:33 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2004-01-16 07:14:08 +00:00
|
|
|
log_err("%s collator creation failed\n", loc);
|
2001-05-25 16:54:33 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
src.opts = &opts;
|
|
|
|
rules = ucol_getRules(coll, &ruleLen);
|
|
|
|
|
|
|
|
if (ruleLen > 0) {
|
2002-07-29 21:04:18 +00:00
|
|
|
rulesCopy = (UChar *)malloc((ruleLen +
|
2001-05-25 16:54:33 +00:00
|
|
|
UCOL_TOK_EXTRA_RULE_SPACE_SIZE) * sizeof(UChar));
|
|
|
|
uprv_memcpy(rulesCopy, rules, ruleLen * sizeof(UChar));
|
2002-10-30 21:11:20 +00:00
|
|
|
src.current = src.source = rulesCopy;
|
2001-05-25 16:54:33 +00:00
|
|
|
src.end = rulesCopy + ruleLen;
|
|
|
|
src.extraCurrent = src.end;
|
|
|
|
src.extraEnd = src.end + UCOL_TOK_EXTRA_RULE_SPACE_SIZE;
|
|
|
|
|
2002-03-07 19:06:00 +00:00
|
|
|
while ((current = ucol_tok_parseNextToken(&src, startOfRules, &parseError,&status)) != NULL) {
|
|
|
|
strength = src.parsedToken.strength;
|
|
|
|
chOffset = src.parsedToken.charsOffset;
|
|
|
|
chLen = src.parsedToken.charsLen;
|
|
|
|
exOffset = src.parsedToken.extensionOffset;
|
|
|
|
exLen = src.parsedToken.extensionLen;
|
|
|
|
prefixOffset = src.parsedToken.prefixOffset;
|
|
|
|
prefixLen = src.parsedToken.prefixLen;
|
|
|
|
specs = src.parsedToken.flags;
|
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
startOfRules = FALSE;
|
2002-07-15 22:53:25 +00:00
|
|
|
uprv_memcpy(codepoints, src.source + chOffset,
|
2001-05-25 16:54:33 +00:00
|
|
|
chLen * sizeof(UChar));
|
|
|
|
codepoints[chLen] = 0;
|
2002-07-15 22:53:25 +00:00
|
|
|
checkCEValidity(coll, codepoints, chLen, 4, 85);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
2002-07-29 21:04:18 +00:00
|
|
|
free(rulesCopy);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
ucol_close(coll);
|
|
|
|
count ++;
|
|
|
|
}
|
2001-11-02 21:47:38 +00:00
|
|
|
T_FileStream_close(file);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void printSortKeyError(const UChar *codepoints, int length,
|
2001-11-02 02:24:15 +00:00
|
|
|
uint8_t *sortkey, int sklen)
|
2001-05-25 16:54:33 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
log_err("Sortkey not valid for ");
|
|
|
|
while (length > 0) {
|
|
|
|
log_err("0x%04x ", *codepoints);
|
|
|
|
length --;
|
|
|
|
codepoints ++;
|
|
|
|
}
|
|
|
|
log_err("\nSortkey : ");
|
|
|
|
while (count < sklen) {
|
|
|
|
log_err("0x%02x ", sortkey[count]);
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
log_err("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checking sort key validity for all levels
|
|
|
|
*/
|
2001-11-02 02:24:15 +00:00
|
|
|
static UBool checkSortKeyValidity(UCollator *coll,
|
|
|
|
const UChar *codepoints,
|
|
|
|
int length)
|
2001-05-25 16:54:33 +00:00
|
|
|
{
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-10-02 16:51:27 +00:00
|
|
|
UCollationStrength strength[5] = {UCOL_PRIMARY, UCOL_SECONDARY,
|
2001-11-02 02:24:15 +00:00
|
|
|
UCOL_TERTIARY, UCOL_QUATERNARY,
|
2001-10-02 16:51:27 +00:00
|
|
|
UCOL_IDENTICAL};
|
|
|
|
int strengthlen = 5;
|
2001-05-25 16:54:33 +00:00
|
|
|
int index = 0;
|
|
|
|
int caselevel = 0;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
while (caselevel < 1) {
|
|
|
|
if (caselevel == 0) {
|
2001-11-02 02:24:15 +00:00
|
|
|
ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_OFF, &status);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2001-11-02 02:24:15 +00:00
|
|
|
ucol_setAttribute(coll, UCOL_CASE_LEVEL, UCOL_ON, &status);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
while (index < strengthlen) {
|
|
|
|
int count01 = 0;
|
|
|
|
uint32_t count = 0;
|
|
|
|
uint8_t sortkey[128];
|
|
|
|
uint32_t sklen;
|
|
|
|
|
|
|
|
ucol_setStrength(coll, strength[index]);
|
|
|
|
sklen = ucol_getSortKey(coll, codepoints, length, sortkey, 128);
|
|
|
|
while (sortkey[count] != 0) {
|
2001-10-02 16:51:27 +00:00
|
|
|
if (sortkey[count] == 2 || (sortkey[count] == 3 && count01 > 0 && index != 4)) {
|
2001-05-25 16:54:33 +00:00
|
|
|
printSortKeyError(codepoints, length, sortkey, sklen);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (sortkey[count] == 1) {
|
|
|
|
count01 ++;
|
|
|
|
}
|
|
|
|
count ++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count + 1 != sklen || (count01 != index + caselevel)) {
|
|
|
|
printSortKeyError(codepoints, length, sortkey, sklen);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
index ++;
|
|
|
|
}
|
|
|
|
caselevel ++;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
return TRUE;
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
|
|
|
|
2001-05-30 17:38:28 +00:00
|
|
|
static void TestSortKeyValidity(void)
|
2001-05-25 16:54:33 +00:00
|
|
|
{
|
|
|
|
/* testing UCA collation elements */
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
/* en_US has no tailorings */
|
|
|
|
UCollator *coll = ucol_open("en_US", &status);
|
|
|
|
/* tailored locales */
|
2006-12-19 06:06:30 +00:00
|
|
|
char locale[][6] = {"fr_FR", "ko_KR", "sh_YU", "th_TH", "zh_CN"};
|
2008-02-17 19:32:34 +00:00
|
|
|
FileStream *file = NULL;
|
2002-06-13 18:35:27 +00:00
|
|
|
char line[1024];
|
2002-07-15 22:53:25 +00:00
|
|
|
UChar codepoints[10];
|
2001-05-25 16:54:33 +00:00
|
|
|
int count = 0;
|
2008-04-04 22:47:43 +00:00
|
|
|
UChar contextCPs[5];
|
2001-08-16 00:58:53 +00:00
|
|
|
UParseError parseError;
|
2001-05-25 16:54:33 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("en_US collator creation failed\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
log_verbose("Testing UCA elements\n");
|
2008-02-17 19:32:34 +00:00
|
|
|
file = getFractionalUCA();
|
2001-05-25 16:54:33 +00:00
|
|
|
if (file == NULL) {
|
|
|
|
log_err("Fractional UCA data can not be opened\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (T_FileStream_readLine(file, line, sizeof(line)) != NULL) {
|
2001-11-02 02:24:15 +00:00
|
|
|
if(line[0] == 0 || line[0] == '#' || line[0] == '\n' ||
|
2001-05-30 22:07:12 +00:00
|
|
|
line[0] == 0x000D || line[0] == '[') {
|
2001-05-25 16:54:33 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-04-04 22:47:43 +00:00
|
|
|
getCodePoints(line, codepoints, contextCPs);
|
2001-05-25 16:54:33 +00:00
|
|
|
checkSortKeyValidity(coll, codepoints, u_strlen(codepoints));
|
|
|
|
}
|
|
|
|
|
|
|
|
log_verbose("Testing UCA elements for the whole range of unicode characters\n");
|
|
|
|
codepoints[0] = 0;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
while (codepoints[0] < 0xFFFF) {
|
|
|
|
if (u_isdefined((UChar32)codepoints[0])) {
|
|
|
|
checkSortKeyValidity(coll, codepoints, 1);
|
|
|
|
}
|
|
|
|
codepoints[0] ++;
|
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
ucol_close(coll);
|
|
|
|
|
|
|
|
/* testing tailored collation elements */
|
|
|
|
log_verbose("Testing tailored elements\n");
|
|
|
|
while (count < 5) {
|
2001-11-02 02:24:15 +00:00
|
|
|
const UChar *rules = NULL,
|
2001-05-25 16:54:33 +00:00
|
|
|
*current = NULL;
|
|
|
|
UChar *rulesCopy = NULL;
|
|
|
|
int32_t ruleLen = 0;
|
|
|
|
|
2001-11-02 02:24:15 +00:00
|
|
|
uint32_t chOffset = 0;
|
2001-05-25 16:54:33 +00:00
|
|
|
uint32_t chLen = 0;
|
2001-11-02 02:24:15 +00:00
|
|
|
uint32_t exOffset = 0;
|
2001-05-25 16:54:33 +00:00
|
|
|
uint32_t exLen = 0;
|
2001-09-27 23:19:12 +00:00
|
|
|
uint32_t prefixOffset = 0;
|
|
|
|
uint32_t prefixLen = 0;
|
2001-05-25 16:54:33 +00:00
|
|
|
UBool startOfRules = TRUE;
|
|
|
|
UColOptionSet opts;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
UColTokenParser src;
|
|
|
|
uint32_t strength = 0;
|
2002-03-15 23:51:22 +00:00
|
|
|
uint16_t specs = 0;
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
coll = ucol_open(locale[count], &status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
log_err("%s collator creation failed\n", locale[count]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
src.opts = &opts;
|
|
|
|
rules = ucol_getRules(coll, &ruleLen);
|
|
|
|
|
|
|
|
if (ruleLen > 0) {
|
2002-07-29 21:04:18 +00:00
|
|
|
rulesCopy = (UChar *)malloc((ruleLen +
|
2001-05-25 16:54:33 +00:00
|
|
|
UCOL_TOK_EXTRA_RULE_SPACE_SIZE) * sizeof(UChar));
|
|
|
|
uprv_memcpy(rulesCopy, rules, ruleLen * sizeof(UChar));
|
2002-10-30 21:11:20 +00:00
|
|
|
src.current = src.source = rulesCopy;
|
2001-05-25 16:54:33 +00:00
|
|
|
src.end = rulesCopy + ruleLen;
|
|
|
|
src.extraCurrent = src.end;
|
|
|
|
src.extraEnd = src.end + UCOL_TOK_EXTRA_RULE_SPACE_SIZE;
|
|
|
|
|
2002-03-07 19:06:00 +00:00
|
|
|
while ((current = ucol_tok_parseNextToken(&src, startOfRules,&parseError, &status)) != NULL) {
|
|
|
|
strength = src.parsedToken.strength;
|
|
|
|
chOffset = src.parsedToken.charsOffset;
|
|
|
|
chLen = src.parsedToken.charsLen;
|
|
|
|
exOffset = src.parsedToken.extensionOffset;
|
|
|
|
exLen = src.parsedToken.extensionLen;
|
|
|
|
prefixOffset = src.parsedToken.prefixOffset;
|
|
|
|
prefixLen = src.parsedToken.prefixLen;
|
|
|
|
specs = src.parsedToken.flags;
|
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
startOfRules = FALSE;
|
2002-07-15 22:53:25 +00:00
|
|
|
uprv_memcpy(codepoints, src.source + chOffset,
|
2001-05-25 16:54:33 +00:00
|
|
|
chLen * sizeof(UChar));
|
|
|
|
codepoints[chLen] = 0;
|
2002-07-15 22:53:25 +00:00
|
|
|
checkSortKeyValidity(coll, codepoints, chLen);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
2002-07-29 21:04:18 +00:00
|
|
|
free(rulesCopy);
|
2001-05-25 16:54:33 +00:00
|
|
|
}
|
2001-11-02 02:24:15 +00:00
|
|
|
|
2001-05-25 16:54:33 +00:00
|
|
|
ucol_close(coll);
|
|
|
|
count ++;
|
|
|
|
}
|
2001-11-02 21:47:38 +00:00
|
|
|
T_FileStream_close(file);
|
2001-05-30 16:15:33 +00:00
|
|
|
}
|
2002-09-20 17:54:45 +00:00
|
|
|
|
|
|
|
#endif /* #if !UCONFIG_NO_COLLATION */
|