2001-03-17 00:46:46 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: ucol_tok.cpp
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created 02/22/2001
|
|
|
|
* created by: Vladimir Weinstein
|
|
|
|
*
|
|
|
|
* This module reads a tailoring rule string and produces a list of
|
|
|
|
* tokens that will be turned into collation elements
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-01-31 07:20:56 +00:00
|
|
|
#include "unicode/ustring.h"
|
2001-03-01 00:14:29 +00:00
|
|
|
#include "unicode/uchar.h"
|
2001-02-28 19:01:23 +00:00
|
|
|
|
2001-03-08 17:40:42 +00:00
|
|
|
#include "ucol_tok.h"
|
2002-07-12 21:42:24 +00:00
|
|
|
#include "cmemory.h"
|
2001-01-29 22:09:24 +00:00
|
|
|
|
2001-10-25 21:55:45 +00:00
|
|
|
U_CDECL_BEGIN
|
2001-11-21 01:08:55 +00:00
|
|
|
static int32_t U_EXPORT2 U_CALLCONV
|
2001-10-29 22:41:44 +00:00
|
|
|
uhash_hashTokens(const UHashTok k)
|
|
|
|
{
|
|
|
|
int32_t hash = 0;
|
|
|
|
//uint32_t key = (uint32_t)k.integer;
|
|
|
|
UColToken *key = (UColToken *)k.pointer;
|
|
|
|
if (key != 0) {
|
|
|
|
//int32_t len = (key & 0xFF000000)>>24;
|
|
|
|
int32_t len = (key->source & 0xFF000000)>>24;
|
|
|
|
int32_t inc = ((len - 32) / 32) + 1;
|
|
|
|
|
|
|
|
//const UChar *p = (key & 0x00FFFFFF) + rulesToParse;
|
|
|
|
const UChar *p = (key->source & 0x00FFFFFF) + key->rulesToParse;
|
|
|
|
const UChar *limit = p + len;
|
2001-10-22 05:30:22 +00:00
|
|
|
|
2001-10-29 22:41:44 +00:00
|
|
|
while (p<limit) {
|
|
|
|
hash = (hash * 37) + *p;
|
|
|
|
p += inc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hash;
|
2001-10-22 05:30:22 +00:00
|
|
|
}
|
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
static UBool U_EXPORT2 U_CALLCONV
|
2001-10-29 22:41:44 +00:00
|
|
|
uhash_compareTokens(const UHashTok key1, const UHashTok key2)
|
|
|
|
{
|
2001-10-22 05:30:22 +00:00
|
|
|
//uint32_t p1 = (uint32_t) key1.integer;
|
|
|
|
//uint32_t p2 = (uint32_t) key2.integer;
|
|
|
|
UColToken *p1 = (UColToken *)key1.pointer;
|
|
|
|
UColToken *p2 = (UColToken *)key2.pointer;
|
|
|
|
const UChar *s1 = (p1->source & 0x00FFFFFF) + p1->rulesToParse;
|
|
|
|
const UChar *s2 = (p2->source & 0x00FFFFFF) + p2->rulesToParse;
|
|
|
|
uint32_t s1L = ((p1->source & 0xFF000000) >> 24);
|
|
|
|
uint32_t s2L = ((p2->source & 0xFF000000) >> 24);
|
|
|
|
const UChar *end = s1+s1L-1;
|
|
|
|
|
|
|
|
if (p1 == p2) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (p1->source == 0 || p2->source == 0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(s1L != s2L) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if(p1->source == p2->source) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
while((s1 < end) && *s1 == *s2) {
|
|
|
|
++s1;
|
|
|
|
++s2;
|
|
|
|
}
|
|
|
|
if(*s1 == *s2) {
|
|
|
|
return TRUE;
|
|
|
|
} else {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-10-25 21:55:45 +00:00
|
|
|
U_CDECL_END
|
2001-10-20 01:09:31 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
static inline void U_CALLCONV
|
|
|
|
uhash_freeBlockWrapper(void *obj) {
|
|
|
|
uhash_freeBlock(obj);
|
|
|
|
}
|
|
|
|
|
2002-06-13 18:32:38 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
uint32_t startCE;
|
|
|
|
uint32_t startContCE;
|
|
|
|
uint32_t limitCE;
|
|
|
|
uint32_t limitContCE;
|
|
|
|
} indirectBoundaries;
|
|
|
|
|
|
|
|
/* these values are used for finding CE values for indirect positioning. */
|
|
|
|
/* Indirect positioning is a mechanism for allowing resets on symbolic */
|
|
|
|
/* values. It only works for resets and you cannot tailor indirect names */
|
|
|
|
/* An indirect name can define either an anchor point or a range. An */
|
|
|
|
/* anchor point behaves in exactly the same way as a code point in reset */
|
|
|
|
/* would, except that it cannot be tailored. A range (we currently only */
|
|
|
|
/* know for the [top] range will explicitly set the upper bound for */
|
|
|
|
/* generated CEs, thus allowing for better control over how many CEs can */
|
|
|
|
/* be squeezed between in the range without performance penalty. */
|
|
|
|
/* In that respect, we use [top] for tailoring of locales that use CJK */
|
|
|
|
/* characters. Other indirect values are currently a pure convenience, */
|
|
|
|
/* they can be used to assure that the CEs will be always positioned in */
|
|
|
|
/* the same place relative to a point with known properties (e.g. first */
|
|
|
|
/* primary ignorable). */
|
2002-07-11 22:43:49 +00:00
|
|
|
static indirectBoundaries ucolIndirectBoundaries[15];
|
2002-07-02 22:32:14 +00:00
|
|
|
/*
|
2002-06-13 18:32:38 +00:00
|
|
|
static indirectBoundaries ucolIndirectBoundaries[11] = {
|
|
|
|
{ UCOL_RESET_TOP_VALUE, 0,
|
|
|
|
UCOL_NEXT_TOP_VALUE, 0 },
|
|
|
|
{ UCOL_FIRST_PRIMARY_IGNORABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_LAST_PRIMARY_IGNORABLE, UCOL_LAST_PRIMARY_IGNORABLE_CONT,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_FIRST_SECONDARY_IGNORABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_LAST_SECONDARY_IGNORABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_FIRST_TERTIARY_IGNORABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_LAST_TERTIARY_IGNORABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_FIRST_VARIABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_LAST_VARIABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_FIRST_NON_VARIABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
{ UCOL_LAST_NON_VARIABLE, 0,
|
|
|
|
0, 0 },
|
|
|
|
};
|
2002-07-02 22:32:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void setIndirectBoundaries(uint32_t indexR, uint32_t *start, uint32_t *end) {
|
|
|
|
|
|
|
|
// Set values for the top - TODO: once we have values for all the indirects, we are going
|
|
|
|
// to initalize here.
|
|
|
|
ucolIndirectBoundaries[indexR].startCE = start[0];
|
|
|
|
ucolIndirectBoundaries[indexR].startContCE = start[1];
|
|
|
|
if(end) {
|
|
|
|
ucolIndirectBoundaries[indexR].limitCE = end[0];
|
|
|
|
ucolIndirectBoundaries[indexR].limitContCE = end[1];
|
|
|
|
} else {
|
|
|
|
ucolIndirectBoundaries[indexR].limitCE = 0;
|
|
|
|
ucolIndirectBoundaries[indexR].limitContCE = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-13 18:32:38 +00:00
|
|
|
|
2001-06-06 20:21:48 +00:00
|
|
|
void ucol_tok_initTokenList(UColTokenParser *src, const UChar *rules, const uint32_t rulesLength, UCollator *UCA, UErrorCode *status) {
|
|
|
|
uint32_t nSize = 0;
|
2001-10-03 01:49:25 +00:00
|
|
|
uint32_t estimatedSize = (2*rulesLength+UCOL_TOK_EXTRA_RULE_SPACE_SIZE);
|
2001-01-29 22:09:24 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-06-06 20:21:48 +00:00
|
|
|
|
2002-01-23 18:26:47 +00:00
|
|
|
// set everything to zero, so that we can clean up gracefully
|
|
|
|
uprv_memset(src, 0, sizeof(UColTokenParser));
|
|
|
|
|
2001-10-03 01:49:25 +00:00
|
|
|
src->source = (UChar *)uprv_malloc(estimatedSize*sizeof(UChar));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (src->source == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-10-03 01:49:25 +00:00
|
|
|
nSize = unorm_normalize(rules, rulesLength, UNORM_NFD, 0, src->source, estimatedSize, status);
|
|
|
|
if(nSize > estimatedSize || *status == U_BUFFER_OVERFLOW_ERROR) {
|
2001-06-06 20:21:48 +00:00
|
|
|
*status = U_ZERO_ERROR;
|
2002-02-28 01:42:40 +00:00
|
|
|
src->source = (UChar *)uprv_realloc(src->source, (nSize+UCOL_TOK_EXTRA_RULE_SPACE_SIZE)*sizeof(UChar));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (src->source == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-06-06 20:21:48 +00:00
|
|
|
nSize = unorm_normalize(rules, rulesLength, UNORM_NFD, 0, src->source, nSize+UCOL_TOK_EXTRA_RULE_SPACE_SIZE, status);
|
|
|
|
}
|
|
|
|
src->current = src->source;
|
|
|
|
src->end = src->source+nSize;
|
|
|
|
src->sourceCurrent = src->source;
|
|
|
|
src->extraCurrent = src->end;
|
2001-10-03 05:58:10 +00:00
|
|
|
src->extraEnd = src->source+estimatedSize; //src->end+UCOL_TOK_EXTRA_RULE_SPACE_SIZE;
|
2002-01-23 18:26:47 +00:00
|
|
|
src->varTop = NULL;
|
2001-06-06 20:21:48 +00:00
|
|
|
src->UCA = UCA;
|
|
|
|
src->invUCA = ucol_initInverseUCA(status);
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.charsLen = 0;
|
|
|
|
src->parsedToken.charsOffset = 0;
|
|
|
|
src->parsedToken.extensionLen = 0;
|
|
|
|
src->parsedToken.extensionOffset = 0;
|
|
|
|
src->parsedToken.prefixLen = 0;
|
|
|
|
src->parsedToken.prefixOffset = 0;
|
|
|
|
src->parsedToken.flags = 0;
|
|
|
|
src->parsedToken.strength = UCOL_TOK_UNSET;
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-01-23 18:26:47 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-06-06 20:21:48 +00:00
|
|
|
src->tailored = uhash_open(uhash_hashTokens, uhash_compareTokens, status);
|
2001-09-22 01:09:50 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-10-25 21:55:45 +00:00
|
|
|
uhash_setValueDeleter(src->tailored, uhash_freeBlock);
|
2001-06-06 20:21:48 +00:00
|
|
|
|
|
|
|
src->opts = (UColOptionSet *)uprv_malloc(sizeof(UColOptionSet));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (src->opts == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-06-06 20:21:48 +00:00
|
|
|
|
|
|
|
uprv_memcpy(src->opts, UCA->options, sizeof(UColOptionSet));
|
|
|
|
|
2001-10-17 22:57:15 +00:00
|
|
|
// rulesToParse = src->source;
|
2002-01-23 18:26:47 +00:00
|
|
|
src->lh = 0;
|
2002-07-02 22:32:14 +00:00
|
|
|
src->listCapacity = 1024;
|
|
|
|
src->lh = (UColTokListHeader *)uprv_malloc(src->listCapacity*sizeof(UColTokListHeader));
|
|
|
|
//Test for NULL
|
2002-06-29 09:31:05 +00:00
|
|
|
if (src->lh == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-02-28 21:50:23 +00:00
|
|
|
src->resultLen = 0;
|
2002-06-13 18:32:38 +00:00
|
|
|
|
|
|
|
UCAConstants *consts = (UCAConstants *)((uint8_t *)src->UCA->image + src->UCA->image->UCAConsts);
|
2002-07-02 22:32:14 +00:00
|
|
|
|
|
|
|
// UCOL_RESET_TOP_VALUE
|
|
|
|
setIndirectBoundaries(0, consts->UCA_LAST_NON_VARIABLE, consts->UCA_FIRST_IMPLICIT);
|
|
|
|
// UCOL_FIRST_PRIMARY_IGNORABLE
|
|
|
|
setIndirectBoundaries(1, consts->UCA_FIRST_PRIMARY_IGNORABLE, 0);
|
|
|
|
// UCOL_LAST_PRIMARY_IGNORABLE
|
|
|
|
setIndirectBoundaries(2, consts->UCA_LAST_PRIMARY_IGNORABLE, 0);
|
|
|
|
// UCOL_FIRST_SECONDARY_IGNORABLE
|
|
|
|
setIndirectBoundaries(3, consts->UCA_FIRST_SECONDARY_IGNORABLE, 0);
|
|
|
|
// UCOL_LAST_SECONDARY_IGNORABLE
|
|
|
|
setIndirectBoundaries(4, consts->UCA_LAST_SECONDARY_IGNORABLE, 0);
|
|
|
|
// UCOL_FIRST_TERTIARY_IGNORABLE
|
|
|
|
setIndirectBoundaries(5, consts->UCA_FIRST_TERTIARY_IGNORABLE, 0);
|
|
|
|
// UCOL_LAST_TERTIARY_IGNORABLE
|
|
|
|
setIndirectBoundaries(6, consts->UCA_LAST_TERTIARY_IGNORABLE, 0);
|
|
|
|
// UCOL_FIRST_VARIABLE
|
|
|
|
setIndirectBoundaries(7, consts->UCA_FIRST_VARIABLE, 0);
|
|
|
|
// UCOL_LAST_VARIABLE
|
|
|
|
setIndirectBoundaries(8, consts->UCA_LAST_VARIABLE, 0);
|
|
|
|
// UCOL_FIRST_NON_VARIABLE
|
|
|
|
setIndirectBoundaries(9, consts->UCA_FIRST_NON_VARIABLE, 0);
|
|
|
|
// UCOL_LAST_NON_VARIABLE
|
2002-07-10 00:50:56 +00:00
|
|
|
setIndirectBoundaries(10, consts->UCA_LAST_NON_VARIABLE, consts->UCA_FIRST_IMPLICIT);
|
2002-07-11 22:43:49 +00:00
|
|
|
// UCOL_FIRST_IMPLICIT
|
|
|
|
setIndirectBoundaries(11, consts->UCA_FIRST_IMPLICIT, 0);
|
|
|
|
// UCOL_LAST_IMPLICIT
|
|
|
|
setIndirectBoundaries(12, consts->UCA_LAST_IMPLICIT, consts->UCA_FIRST_TRAILING);
|
|
|
|
// UCOL_FIRST_TRAILING
|
|
|
|
setIndirectBoundaries(13, consts->UCA_FIRST_TRAILING, 0);
|
|
|
|
// UCOL_LAST_TRAILING
|
|
|
|
setIndirectBoundaries(14, consts->UCA_LAST_TRAILING, 0);
|
|
|
|
ucolIndirectBoundaries[14].limitCE = (consts->UCA_PRIMARY_SPECIAL_MIN<<24);
|
2001-01-29 22:09:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-22 05:30:22 +00:00
|
|
|
static inline
|
|
|
|
void syntaxError(const UChar* rules,
|
|
|
|
int32_t pos,
|
|
|
|
int32_t rulesLen,
|
|
|
|
UParseError* parseError) {
|
2001-08-16 00:55:16 +00:00
|
|
|
parseError->offset = pos;
|
2001-08-17 02:20:35 +00:00
|
|
|
parseError->line = 0 ; /* we are not using line numbers */
|
|
|
|
|
2001-08-16 00:55:16 +00:00
|
|
|
// for pre-context
|
2001-08-17 02:20:35 +00:00
|
|
|
int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1));
|
2001-08-16 00:55:16 +00:00
|
|
|
int32_t stop = pos;
|
2001-08-17 02:20:35 +00:00
|
|
|
|
|
|
|
u_memcpy(parseError->preContext,rules+start,stop-start);
|
2001-08-16 00:55:16 +00:00
|
|
|
//null terminate the buffer
|
|
|
|
parseError->preContext[stop-start] = 0;
|
|
|
|
|
|
|
|
//for post-context
|
2001-08-17 02:20:35 +00:00
|
|
|
start = pos+1;
|
|
|
|
stop = ((pos+U_PARSE_CONTEXT_LEN)<= rulesLen )? (pos+(U_PARSE_CONTEXT_LEN-1)) :
|
2001-08-16 00:55:16 +00:00
|
|
|
u_strlen(rules);
|
2001-08-17 02:20:35 +00:00
|
|
|
|
|
|
|
u_memcpy(parseError->postContext,rules+start,stop-start);
|
2001-08-16 00:55:16 +00:00
|
|
|
//null terminate the buffer
|
|
|
|
parseError->postContext[stop-start]= 0;
|
|
|
|
}
|
2001-03-06 00:57:48 +00:00
|
|
|
|
2001-10-22 05:30:22 +00:00
|
|
|
static
|
|
|
|
void ucol_uprv_tok_setOptionInImage(UColOptionSet *opts, UColAttribute attrib, UColAttributeValue value) {
|
2001-03-07 19:43:06 +00:00
|
|
|
switch(attrib) {
|
2001-10-02 16:49:57 +00:00
|
|
|
case UCOL_HIRAGANA_QUATERNARY_MODE:
|
|
|
|
opts->hiraganaQ = value;
|
2001-10-05 02:09:22 +00:00
|
|
|
break;
|
2001-03-07 19:43:06 +00:00
|
|
|
case UCOL_FRENCH_COLLATION:
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->frenchCollation = value;
|
2001-03-07 19:43:06 +00:00
|
|
|
break;
|
|
|
|
case UCOL_ALTERNATE_HANDLING:
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->alternateHandling = value;
|
2001-03-07 19:43:06 +00:00
|
|
|
break;
|
|
|
|
case UCOL_CASE_FIRST:
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->caseFirst = value;
|
2001-03-07 19:43:06 +00:00
|
|
|
break;
|
|
|
|
case UCOL_CASE_LEVEL:
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->caseLevel = value;
|
2001-03-07 19:43:06 +00:00
|
|
|
break;
|
|
|
|
case UCOL_NORMALIZATION_MODE:
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->normalizationMode = value;
|
2001-03-07 19:43:06 +00:00
|
|
|
break;
|
|
|
|
case UCOL_STRENGTH:
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->strength = value;
|
2001-03-07 19:43:06 +00:00
|
|
|
break;
|
|
|
|
case UCOL_ATTRIBUTE_COUNT:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-15 23:41:56 +00:00
|
|
|
#define UTOK_OPTION_COUNT 17
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2001-03-22 21:16:20 +00:00
|
|
|
static UBool didInit = FALSE;
|
2001-03-07 19:43:06 +00:00
|
|
|
/* we can be strict, or we can be lenient */
|
|
|
|
/* I'd surely be lenient with the option arguments */
|
|
|
|
/* maybe even with options */
|
|
|
|
U_STRING_DECL(suboption_00, "non-ignorable", 13);
|
|
|
|
U_STRING_DECL(suboption_01, "shifted", 7);
|
|
|
|
|
|
|
|
U_STRING_DECL(suboption_02, "lower", 5);
|
|
|
|
U_STRING_DECL(suboption_03, "upper", 5);
|
|
|
|
U_STRING_DECL(suboption_04, "off", 3);
|
|
|
|
U_STRING_DECL(suboption_05, "on", 2);
|
2001-05-02 05:05:06 +00:00
|
|
|
U_STRING_DECL(suboption_06, "1", 1);
|
|
|
|
U_STRING_DECL(suboption_07, "2", 1);
|
|
|
|
U_STRING_DECL(suboption_08, "3", 1);
|
2001-10-05 02:09:22 +00:00
|
|
|
U_STRING_DECL(suboption_09, "4", 1);
|
|
|
|
U_STRING_DECL(suboption_10, "I", 1);
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2002-03-15 23:41:56 +00:00
|
|
|
U_STRING_DECL(suboption_11, "primary", 7);
|
|
|
|
U_STRING_DECL(suboption_12, "secondary", 9);
|
|
|
|
U_STRING_DECL(suboption_13, "tertiary", 8);
|
|
|
|
U_STRING_DECL(suboption_14, "variable", 8);
|
2002-07-11 22:43:49 +00:00
|
|
|
U_STRING_DECL(suboption_15, "regular", 7);
|
|
|
|
U_STRING_DECL(suboption_16, "implicit", 8);
|
|
|
|
U_STRING_DECL(suboption_17, "trailing", 8);
|
|
|
|
|
2001-03-07 19:43:06 +00:00
|
|
|
|
|
|
|
U_STRING_DECL(option_00, "undefined", 9);
|
|
|
|
U_STRING_DECL(option_01, "rearrange", 9);
|
|
|
|
U_STRING_DECL(option_02, "alternate", 9);
|
|
|
|
U_STRING_DECL(option_03, "backwards", 9);
|
|
|
|
U_STRING_DECL(option_04, "variable top", 12);
|
|
|
|
U_STRING_DECL(option_05, "top", 3);
|
|
|
|
U_STRING_DECL(option_06, "normalization", 13);
|
|
|
|
U_STRING_DECL(option_07, "caseLevel", 9);
|
|
|
|
U_STRING_DECL(option_08, "caseFirst", 9);
|
|
|
|
U_STRING_DECL(option_09, "scriptOrder", 11);
|
|
|
|
U_STRING_DECL(option_10, "charsetname", 11);
|
|
|
|
U_STRING_DECL(option_11, "charset", 7);
|
2001-05-02 05:05:06 +00:00
|
|
|
U_STRING_DECL(option_12, "before", 6);
|
2001-10-02 16:49:57 +00:00
|
|
|
U_STRING_DECL(option_13, "hiraganaQ", 9);
|
2001-10-05 02:09:22 +00:00
|
|
|
U_STRING_DECL(option_14, "strength", 8);
|
2002-03-15 23:41:56 +00:00
|
|
|
U_STRING_DECL(option_15, "first", 5);
|
|
|
|
U_STRING_DECL(option_16, "last", 4);
|
|
|
|
|
|
|
|
/*
|
|
|
|
[last variable] last variable value
|
|
|
|
[last primary ignorable] largest CE for primary ignorable
|
|
|
|
[last secondary ignorable] largest CE for secondary ignorable
|
|
|
|
[last tertiary ignorable] largest CE for tertiary ignorable
|
|
|
|
[top] guaranteed to be above all implicit CEs, for now and in the future (in 1.8)
|
|
|
|
*/
|
2001-05-02 05:05:06 +00:00
|
|
|
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokSuboption alternateSub[2] = {
|
2001-03-07 19:43:06 +00:00
|
|
|
{suboption_00, 13, UCOL_NON_IGNORABLE},
|
|
|
|
{suboption_01, 7, UCOL_SHIFTED}
|
|
|
|
};
|
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokSuboption caseFirstSub[3] = {
|
2001-04-25 22:28:30 +00:00
|
|
|
{suboption_02, 5, UCOL_LOWER_FIRST},
|
|
|
|
{suboption_03, 5, UCOL_UPPER_FIRST},
|
|
|
|
{suboption_04, 3, UCOL_OFF},
|
2001-03-07 19:43:06 +00:00
|
|
|
};
|
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokSuboption onOffSub[2] = {
|
2001-03-07 19:43:06 +00:00
|
|
|
{suboption_04, 3, UCOL_OFF},
|
|
|
|
{suboption_05, 2, UCOL_ON}
|
|
|
|
};
|
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokSuboption frenchSub[1] = {
|
2001-05-02 05:05:06 +00:00
|
|
|
{suboption_07, 1, UCOL_ON}
|
2001-03-07 19:43:06 +00:00
|
|
|
};
|
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokSuboption beforeSub[3] = {
|
2001-05-02 05:05:06 +00:00
|
|
|
{suboption_06, 1, UCOL_PRIMARY},
|
|
|
|
{suboption_07, 1, UCOL_SECONDARY},
|
|
|
|
{suboption_08, 1, UCOL_TERTIARY}
|
|
|
|
};
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokSuboption strengthSub[5] = {
|
2001-10-05 02:09:22 +00:00
|
|
|
{suboption_06, 1, UCOL_PRIMARY},
|
|
|
|
{suboption_07, 1, UCOL_SECONDARY},
|
|
|
|
{suboption_08, 1, UCOL_TERTIARY},
|
|
|
|
{suboption_09, 1, UCOL_QUATERNARY},
|
|
|
|
{suboption_10, 1, UCOL_IDENTICAL},
|
|
|
|
};
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2002-07-11 22:43:49 +00:00
|
|
|
static const ucolTokSuboption firstLastSub[7] = {
|
2002-03-15 23:41:56 +00:00
|
|
|
{suboption_11, 7, UCOL_PRIMARY},
|
|
|
|
{suboption_12, 9, UCOL_PRIMARY},
|
|
|
|
{suboption_13, 8, UCOL_PRIMARY},
|
|
|
|
{suboption_14, 8, UCOL_PRIMARY},
|
2002-07-11 22:43:49 +00:00
|
|
|
{suboption_15, 7, UCOL_PRIMARY},
|
|
|
|
{suboption_16, 8, UCOL_PRIMARY},
|
|
|
|
{suboption_17, 8, UCOL_PRIMARY},
|
2002-03-15 23:41:56 +00:00
|
|
|
};
|
|
|
|
|
2001-10-11 23:54:55 +00:00
|
|
|
static const ucolTokOption rulesOptions[UTOK_OPTION_COUNT] = {
|
2001-05-22 21:54:46 +00:00
|
|
|
{option_02, 9, alternateSub, 2, UCOL_ALTERNATE_HANDLING}, /*"alternate" */
|
|
|
|
{option_03, 9, frenchSub, 1, UCOL_FRENCH_COLLATION}, /*"backwards" */
|
|
|
|
{option_07, 9, onOffSub, 2, UCOL_CASE_LEVEL}, /*"caseLevel" */
|
|
|
|
{option_08, 9, caseFirstSub, 3, UCOL_CASE_FIRST}, /*"caseFirst" */
|
|
|
|
{option_06, 13, onOffSub, 2, UCOL_NORMALIZATION_MODE}, /*"normalization" */
|
2001-10-02 16:49:57 +00:00
|
|
|
{option_13, 9, onOffSub, 2, UCOL_HIRAGANA_QUATERNARY_MODE}, /*"hiraganaQ" */
|
2001-10-05 02:09:22 +00:00
|
|
|
{option_14, 8, strengthSub, 5, UCOL_STRENGTH}, /*"strength" */
|
2001-03-07 19:43:06 +00:00
|
|
|
{option_04, 12, NULL, 0, UCOL_ATTRIBUTE_COUNT}, /*"variable top" */
|
2001-05-22 21:54:46 +00:00
|
|
|
{option_01, 9, NULL, 0, UCOL_ATTRIBUTE_COUNT}, /*"rearrange" */
|
|
|
|
{option_12, 6, beforeSub, 3, UCOL_ATTRIBUTE_COUNT}, /*"before" */
|
2002-03-15 23:41:56 +00:00
|
|
|
{option_05, 3, NULL, 0, UCOL_ATTRIBUTE_COUNT}, /*"top" */
|
2002-07-11 22:43:49 +00:00
|
|
|
{option_15, 5, firstLastSub, 7, UCOL_ATTRIBUTE_COUNT}, /*"first" */
|
|
|
|
{option_16, 4, firstLastSub, 7, UCOL_ATTRIBUTE_COUNT}, /*"last" */
|
2001-03-07 19:43:06 +00:00
|
|
|
{option_00, 9, NULL, 0, UCOL_ATTRIBUTE_COUNT}, /*"undefined" */
|
2001-05-22 21:54:46 +00:00
|
|
|
{option_09, 11, NULL, 0, UCOL_ATTRIBUTE_COUNT}, /*"scriptOrder" */
|
|
|
|
{option_10, 11, NULL, 0, UCOL_ATTRIBUTE_COUNT}, /*"charsetname" */
|
|
|
|
{option_11, 7, NULL, 0, UCOL_ATTRIBUTE_COUNT} /*"charset" */
|
2001-03-07 19:43:06 +00:00
|
|
|
};
|
|
|
|
|
2001-10-22 05:30:22 +00:00
|
|
|
static
|
|
|
|
int32_t u_strncmpNoCase(const UChar *s1,
|
2001-04-19 17:08:07 +00:00
|
|
|
const UChar *s2,
|
|
|
|
int32_t n)
|
|
|
|
{
|
|
|
|
if(n > 0) {
|
|
|
|
int32_t rc;
|
|
|
|
for(;;) {
|
|
|
|
rc = (int32_t)u_tolower(*s1) - (int32_t)u_tolower(*s2);
|
|
|
|
if(rc != 0 || *s1 == 0 || --n == 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
++s1;
|
|
|
|
++s2;
|
|
|
|
}
|
|
|
|
}
|
2001-05-22 21:54:46 +00:00
|
|
|
return 0;
|
2001-04-19 17:08:07 +00:00
|
|
|
}
|
|
|
|
|
2001-10-22 05:30:22 +00:00
|
|
|
static
|
2002-04-30 23:29:44 +00:00
|
|
|
void ucol_uprv_tok_initData() {
|
2001-03-06 00:57:48 +00:00
|
|
|
if(!didInit) {
|
2001-03-07 19:43:06 +00:00
|
|
|
U_STRING_INIT(suboption_00, "non-ignorable", 13);
|
|
|
|
U_STRING_INIT(suboption_01, "shifted", 7);
|
|
|
|
|
|
|
|
U_STRING_INIT(suboption_02, "lower", 5);
|
|
|
|
U_STRING_INIT(suboption_03, "upper", 5);
|
|
|
|
U_STRING_INIT(suboption_04, "off", 3);
|
|
|
|
U_STRING_INIT(suboption_05, "on", 2);
|
|
|
|
|
2001-05-02 05:05:06 +00:00
|
|
|
U_STRING_INIT(suboption_06, "1", 1);
|
|
|
|
U_STRING_INIT(suboption_07, "2", 1);
|
|
|
|
U_STRING_INIT(suboption_08, "3", 1);
|
2001-10-05 02:09:22 +00:00
|
|
|
U_STRING_INIT(suboption_09, "4", 1);
|
|
|
|
U_STRING_INIT(suboption_10, "I", 1);
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2002-03-15 23:41:56 +00:00
|
|
|
U_STRING_INIT(suboption_11, "primary", 7);
|
|
|
|
U_STRING_INIT(suboption_12, "secondary", 9);
|
|
|
|
U_STRING_INIT(suboption_13, "tertiary", 8);
|
|
|
|
U_STRING_INIT(suboption_14, "variable", 8);
|
2002-07-11 22:43:49 +00:00
|
|
|
U_STRING_INIT(suboption_15, "regular", 7);
|
|
|
|
U_STRING_INIT(suboption_16, "implicit", 8);
|
|
|
|
U_STRING_INIT(suboption_17, "trailing", 8);
|
2002-03-15 23:41:56 +00:00
|
|
|
|
2001-03-07 19:43:06 +00:00
|
|
|
|
2001-03-06 07:44:37 +00:00
|
|
|
U_STRING_INIT(option_00, "undefined", 9);
|
|
|
|
U_STRING_INIT(option_01, "rearrange", 9);
|
|
|
|
U_STRING_INIT(option_02, "alternate", 9);
|
|
|
|
U_STRING_INIT(option_03, "backwards", 9);
|
|
|
|
U_STRING_INIT(option_04, "variable top", 12);
|
|
|
|
U_STRING_INIT(option_05, "top", 3);
|
|
|
|
U_STRING_INIT(option_06, "normalization", 13);
|
|
|
|
U_STRING_INIT(option_07, "caseLevel", 9);
|
|
|
|
U_STRING_INIT(option_08, "caseFirst", 9);
|
|
|
|
U_STRING_INIT(option_09, "scriptOrder", 11);
|
|
|
|
U_STRING_INIT(option_10, "charsetname", 11);
|
|
|
|
U_STRING_INIT(option_11, "charset", 7);
|
2001-05-02 05:05:06 +00:00
|
|
|
U_STRING_INIT(option_12, "before", 6);
|
2001-10-02 16:49:57 +00:00
|
|
|
U_STRING_INIT(option_13, "hiraganaQ", 9);
|
2001-10-05 02:09:22 +00:00
|
|
|
U_STRING_INIT(option_14, "strength", 8);
|
2002-03-16 05:05:08 +00:00
|
|
|
U_STRING_INIT(option_15, "first", 5);
|
|
|
|
U_STRING_INIT(option_16, "last", 4);
|
2001-03-06 07:44:37 +00:00
|
|
|
}
|
2002-04-30 23:29:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const UChar *
|
|
|
|
ucol_tok_getNextArgument(const UChar *start, const UChar *end,
|
|
|
|
UColAttribute *attrib, UColAttributeValue *value,
|
|
|
|
UErrorCode *status) {
|
|
|
|
uint32_t i = 0;
|
|
|
|
int32_t j=0;
|
|
|
|
UBool foundOption = FALSE;
|
|
|
|
const UChar *optionArg = NULL;
|
|
|
|
|
|
|
|
ucol_uprv_tok_initData();
|
|
|
|
|
2002-05-01 16:07:18 +00:00
|
|
|
while(u_isWhitespace(*start) && start < end) { /* eat whitespace */
|
2002-04-30 23:29:44 +00:00
|
|
|
start++;
|
|
|
|
}
|
2002-05-01 16:07:18 +00:00
|
|
|
if(start >= end) {
|
2002-04-30 23:29:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* skip opening '[' */
|
|
|
|
if(*start == 0x005b) {
|
|
|
|
start++;
|
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR; // no opening '['
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(i < UTOK_OPTION_COUNT) {
|
|
|
|
if(u_strncmpNoCase(start, rulesOptions[i].optionName, rulesOptions[i].optionLen) == 0) {
|
|
|
|
foundOption = TRUE;
|
|
|
|
if(end - start > rulesOptions[i].optionLen) {
|
|
|
|
optionArg = start+rulesOptions[i].optionLen+1; /* start of the options, skip space */
|
|
|
|
while(u_isWhitespace(*optionArg)) { /* eat whitespace */
|
|
|
|
optionArg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!foundOption) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(optionArg) {
|
|
|
|
for(j = 0; j<rulesOptions[i].subSize; j++) {
|
|
|
|
if(u_strncmpNoCase(optionArg, rulesOptions[i].subopts[j].subName, rulesOptions[i].subopts[j].subLen) == 0) {
|
|
|
|
//ucol_uprv_tok_setOptionInImage(src->opts, rulesOptions[i].attr, rulesOptions[i].subopts[j].attrVal);
|
|
|
|
*attrib = rulesOptions[i].attr;
|
|
|
|
*value = rulesOptions[i].subopts[j].attrVal;
|
|
|
|
optionArg += rulesOptions[i].subopts[j].subLen;
|
|
|
|
while(u_isWhitespace(*optionArg)) { /* eat whitespace */
|
|
|
|
optionArg++;
|
|
|
|
}
|
|
|
|
if(*optionArg == 0x005d) {
|
|
|
|
optionArg++;
|
|
|
|
return optionArg;
|
|
|
|
} else {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
uint8_t ucol_uprv_tok_readAndSetOption(UColTokenParser *src, const UChar *end, UErrorCode *status) {
|
|
|
|
const UChar* start = src->current;
|
|
|
|
uint32_t i = 0;
|
|
|
|
int32_t j=0;
|
|
|
|
UBool foundOption = FALSE;
|
|
|
|
const UChar *optionArg = NULL;
|
|
|
|
|
|
|
|
ucol_uprv_tok_initData();
|
|
|
|
|
2001-03-06 07:44:37 +00:00
|
|
|
start++; /*skip opening '['*/
|
|
|
|
while(i < UTOK_OPTION_COUNT) {
|
2001-04-19 17:08:07 +00:00
|
|
|
if(u_strncmpNoCase(start, rulesOptions[i].optionName, rulesOptions[i].optionLen) == 0) {
|
2001-03-06 07:44:37 +00:00
|
|
|
foundOption = TRUE;
|
|
|
|
if(end - start > rulesOptions[i].optionLen) {
|
|
|
|
optionArg = start+rulesOptions[i].optionLen+1; /* start of the options, skip space */
|
|
|
|
while(u_isWhitespace(*optionArg)) { /* eat whitespace */
|
|
|
|
optionArg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!foundOption) {
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return FALSE;
|
2001-03-06 00:57:48 +00:00
|
|
|
}
|
2001-03-06 07:44:37 +00:00
|
|
|
|
2001-10-05 02:09:22 +00:00
|
|
|
if(i<7) {
|
2001-03-06 07:44:37 +00:00
|
|
|
if(optionArg) {
|
2001-03-07 19:43:06 +00:00
|
|
|
for(j = 0; j<rulesOptions[i].subSize; j++) {
|
2001-04-25 22:28:30 +00:00
|
|
|
if(u_strncmpNoCase(optionArg, rulesOptions[i].subopts[j].subName, rulesOptions[i].subopts[j].subLen) == 0) {
|
2002-03-15 23:41:56 +00:00
|
|
|
ucol_uprv_tok_setOptionInImage(src->opts, rulesOptions[i].attr, rulesOptions[i].subopts[j].attrVal);
|
2001-05-02 05:05:06 +00:00
|
|
|
return UCOL_TOK_SUCCESS;
|
2001-03-07 19:43:06 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-06 07:44:37 +00:00
|
|
|
}
|
2001-03-07 19:43:06 +00:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return FALSE;
|
2001-10-05 02:09:22 +00:00
|
|
|
} else if(i == 7) { /* variable top */
|
2001-05-02 05:05:06 +00:00
|
|
|
return UCOL_TOK_SUCCESS | UCOL_TOK_VARIABLE_TOP;
|
2001-10-05 02:09:22 +00:00
|
|
|
} else if(i == 8) { /*rearange */
|
2001-05-02 05:05:06 +00:00
|
|
|
return UCOL_TOK_SUCCESS;
|
2002-03-15 23:41:56 +00:00
|
|
|
} else if(i == 9) { /*before*/
|
2001-05-02 05:05:06 +00:00
|
|
|
if(optionArg) {
|
|
|
|
for(j = 0; j<rulesOptions[i].subSize; j++) {
|
|
|
|
if(u_strncmpNoCase(optionArg, rulesOptions[i].subopts[j].subName, rulesOptions[i].subopts[j].subLen) == 0) {
|
|
|
|
return UCOL_TOK_SUCCESS | rulesOptions[i].subopts[j].attrVal + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
2002-03-15 23:41:56 +00:00
|
|
|
} else if(i == 10) { /*top */ /* we are going to have an array with structures of limit CEs */
|
|
|
|
/* index to this array will be src->parsedToken.indirectIndex*/
|
|
|
|
src->parsedToken.indirectIndex = 0;
|
|
|
|
return UCOL_TOK_SUCCESS | UCOL_TOK_TOP;
|
|
|
|
} else if(i < 13) { /* first, last */
|
|
|
|
for(j = 0; j<rulesOptions[i].subSize; j++) {
|
|
|
|
if(u_strncmpNoCase(optionArg, rulesOptions[i].subopts[j].subName, rulesOptions[i].subopts[j].subLen) == 0) {
|
|
|
|
src->parsedToken.indirectIndex = (uint16_t)(i-10+j*2);
|
|
|
|
return UCOL_TOK_SUCCESS | UCOL_TOK_TOP;;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return FALSE;
|
2001-03-07 19:43:06 +00:00
|
|
|
} else {
|
|
|
|
*status = U_UNSUPPORTED_ERROR;
|
2001-05-02 05:05:06 +00:00
|
|
|
return 0;
|
2001-03-06 07:44:37 +00:00
|
|
|
}
|
2001-03-06 00:57:48 +00:00
|
|
|
}
|
2001-02-27 21:01:11 +00:00
|
|
|
|
2001-11-21 01:08:55 +00:00
|
|
|
U_CAPI const UChar* U_EXPORT2
|
|
|
|
ucol_tok_parseNextToken(UColTokenParser *src,
|
2001-03-20 00:56:37 +00:00
|
|
|
UBool startOfRules,
|
2001-08-16 00:55:16 +00:00
|
|
|
UParseError *parseError,
|
2001-03-20 00:56:37 +00:00
|
|
|
UErrorCode *status) {
|
|
|
|
/* parsing part */
|
2001-03-06 00:57:48 +00:00
|
|
|
UBool variableTop = FALSE;
|
2001-03-07 19:43:06 +00:00
|
|
|
UBool top = FALSE;
|
2001-03-20 00:56:37 +00:00
|
|
|
UBool inChars = TRUE;
|
|
|
|
UBool inQuote = FALSE;
|
|
|
|
UBool wasInQuote = FALSE;
|
|
|
|
UChar *optionEnd = NULL;
|
2001-05-02 05:05:06 +00:00
|
|
|
uint8_t before = 0;
|
2001-11-07 03:37:06 +00:00
|
|
|
UBool isEscaped = FALSE;
|
2001-03-20 00:56:37 +00:00
|
|
|
uint32_t newCharsLen = 0, newExtensionLen = 0;
|
|
|
|
uint32_t charsOffset = 0, extensionOffset = 0;
|
2001-01-31 20:17:12 +00:00
|
|
|
uint32_t newStrength = UCOL_TOK_UNSET;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.prefixOffset = 0; src->parsedToken.prefixLen = 0;
|
2002-03-15 23:41:56 +00:00
|
|
|
src->parsedToken.indirectIndex = 0;
|
2001-09-27 23:18:14 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
while (src->current < src->end) {
|
2002-05-22 23:56:30 +00:00
|
|
|
UChar ch = *(src->current);
|
2001-02-28 21:50:23 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
if (inQuote) {
|
|
|
|
if (ch == 0x0027/*'\''*/) {
|
|
|
|
inQuote = FALSE;
|
|
|
|
} else {
|
|
|
|
if ((newCharsLen == 0) || inChars) {
|
|
|
|
if(newCharsLen == 0) {
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->extraCurrent - src->source);
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
newCharsLen++;
|
|
|
|
} else {
|
|
|
|
if(newExtensionLen == 0) {
|
2002-05-22 23:56:30 +00:00
|
|
|
extensionOffset = (uint32_t)(src->extraCurrent - src->source);
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
newExtensionLen++;
|
|
|
|
}
|
|
|
|
}
|
2001-11-07 03:37:06 +00:00
|
|
|
}else if(isEscaped){
|
|
|
|
isEscaped =FALSE;
|
|
|
|
if (newStrength == UCOL_TOK_UNSET) {
|
2002-07-12 20:33:01 +00:00
|
|
|
/* enabling rules to start with non-tokens a < b
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-11-07 03:37:06 +00:00
|
|
|
return NULL;
|
2002-07-12 20:33:01 +00:00
|
|
|
*/
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
2001-11-07 03:37:06 +00:00
|
|
|
}
|
|
|
|
if(ch != 0x0000 && src->current != src->end) {
|
|
|
|
if (inChars) {
|
|
|
|
if(newCharsLen == 0) {
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->current - src->source);
|
2001-11-07 03:37:06 +00:00
|
|
|
}
|
|
|
|
newCharsLen++;
|
|
|
|
} else {
|
|
|
|
if(newExtensionLen == 0) {
|
2002-05-22 23:56:30 +00:00
|
|
|
extensionOffset = (uint32_t)(src->current - src->source);
|
2001-11-07 03:37:06 +00:00
|
|
|
}
|
|
|
|
newExtensionLen++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else {
|
2001-03-20 00:56:37 +00:00
|
|
|
/* Sets the strength for this entry */
|
|
|
|
switch (ch) {
|
|
|
|
case 0x003D/*'='*/ :
|
|
|
|
if (newStrength != UCOL_TOK_UNSET) {
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
/* if we start with strength, we'll reset to top */
|
|
|
|
if(startOfRules == TRUE) {
|
|
|
|
top = TRUE;
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
|
|
|
newStrength = UCOL_IDENTICAL;
|
|
|
|
break;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
case 0x002C/*','*/:
|
|
|
|
if (newStrength != UCOL_TOK_UNSET) {
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
2001-01-31 21:10:55 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
/* if we start with strength, we'll reset to top */
|
|
|
|
if(startOfRules == TRUE) {
|
|
|
|
top = TRUE;
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
|
|
|
newStrength = UCOL_TERTIARY;
|
|
|
|
break;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
case 0x003B/*';'*/:
|
|
|
|
if (newStrength != UCOL_TOK_UNSET) {
|
|
|
|
goto EndOfLoop;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
/* if we start with strength, we'll reset to top */
|
|
|
|
if(startOfRules == TRUE) {
|
|
|
|
top = TRUE;
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
|
|
|
newStrength = UCOL_SECONDARY;
|
|
|
|
break;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
case 0x003C/*'<'*/:
|
|
|
|
if (newStrength != UCOL_TOK_UNSET) {
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
/* if we start with strength, we'll reset to top */
|
|
|
|
if(startOfRules == TRUE) {
|
|
|
|
top = TRUE;
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
|
|
|
/* before this, do a scan to verify whether this is */
|
|
|
|
/* another strength */
|
|
|
|
if(*(src->current+1) == 0x003C) {
|
|
|
|
src->current++;
|
|
|
|
if(*(src->current+1) == 0x003C) {
|
|
|
|
src->current++; /* three in a row! */
|
2001-01-31 07:20:56 +00:00
|
|
|
newStrength = UCOL_TERTIARY;
|
2001-03-20 00:56:37 +00:00
|
|
|
} else { /* two in a row */
|
2001-01-31 07:20:56 +00:00
|
|
|
newStrength = UCOL_SECONDARY;
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
} else { /* just one */
|
|
|
|
newStrength = UCOL_PRIMARY;
|
|
|
|
}
|
|
|
|
break;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
case 0x0026/*'&'*/:
|
|
|
|
if (newStrength != UCOL_TOK_UNSET) {
|
2001-08-17 02:20:35 +00:00
|
|
|
/**/
|
2001-03-20 00:56:37 +00:00
|
|
|
goto EndOfLoop;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
newStrength = UCOL_TOK_RESET; /* PatternEntry::RESET = 0 */
|
|
|
|
break;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
case 0x005b/*'['*/:
|
|
|
|
/* options - read an option, analyze it */
|
|
|
|
if((optionEnd = u_strchr(src->current, 0x005d /*']'*/)) != NULL) {
|
2002-03-15 23:41:56 +00:00
|
|
|
uint8_t result = ucol_uprv_tok_readAndSetOption(src, optionEnd, status);
|
2001-03-20 00:56:37 +00:00
|
|
|
src->current = optionEnd;
|
2001-05-02 05:05:06 +00:00
|
|
|
if(U_SUCCESS(*status)) {
|
|
|
|
if(result & UCOL_TOK_TOP) {
|
|
|
|
if(newStrength == UCOL_TOK_RESET) {
|
|
|
|
top = TRUE;
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->extraCurrent - src->source);
|
2002-03-15 23:41:56 +00:00
|
|
|
*src->extraCurrent++ = 0xFFFE;
|
|
|
|
*src->extraCurrent++ = (UChar)(ucolIndirectBoundaries[src->parsedToken.indirectIndex].startCE >> 16);
|
|
|
|
*src->extraCurrent++ = (UChar)(ucolIndirectBoundaries[src->parsedToken.indirectIndex].startCE & 0xFFFF);
|
2002-07-02 22:32:14 +00:00
|
|
|
if(ucolIndirectBoundaries[src->parsedToken.indirectIndex].startContCE == 0) {
|
|
|
|
newCharsLen = 3;
|
|
|
|
} else {
|
|
|
|
*src->extraCurrent++ = (UChar)(ucolIndirectBoundaries[src->parsedToken.indirectIndex].startContCE >> 16);
|
|
|
|
*src->extraCurrent++ = (UChar)(ucolIndirectBoundaries[src->parsedToken.indirectIndex].startContCE & 0xFFFF);
|
|
|
|
newCharsLen = 5;
|
2002-07-11 22:43:49 +00:00
|
|
|
}
|
|
|
|
if(before) { // This is a combination of before and indirection like '&[before 2][first regular]<b'
|
|
|
|
*src->extraCurrent++ = 0x002d;
|
|
|
|
*src->extraCurrent++ = before;
|
|
|
|
newCharsLen+=2;
|
2002-07-02 22:32:14 +00:00
|
|
|
}
|
|
|
|
|
2001-05-02 05:05:06 +00:00
|
|
|
src->current++;
|
|
|
|
goto EndOfLoop;
|
|
|
|
} else {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-05-02 05:05:06 +00:00
|
|
|
}
|
|
|
|
} else if(result & UCOL_TOK_VARIABLE_TOP) {
|
|
|
|
if(newStrength != UCOL_TOK_RESET && newStrength != UCOL_TOK_UNSET) {
|
|
|
|
variableTop = TRUE;
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->extraCurrent - src->source);
|
2001-05-02 05:05:06 +00:00
|
|
|
newCharsLen = 1;
|
|
|
|
*src->extraCurrent++ = 0xFFFF;
|
|
|
|
src->current++;
|
|
|
|
goto EndOfLoop;
|
|
|
|
} else {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-05-02 05:05:06 +00:00
|
|
|
}
|
|
|
|
} else if (result & UCOL_TOK_BEFORE){
|
|
|
|
if(newStrength == UCOL_TOK_RESET) {
|
|
|
|
before = result & UCOL_TOK_BEFORE;
|
|
|
|
} else {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-08-17 02:20:35 +00:00
|
|
|
|
2001-05-02 05:05:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-03-20 00:56:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
/* Ignore the white spaces */
|
|
|
|
case 0x0009/*'\t'*/:
|
|
|
|
case 0x000C/*'\f'*/:
|
|
|
|
case 0x000D/*'\r'*/:
|
|
|
|
case 0x000A/*'\n'*/:
|
|
|
|
case 0x0020/*' '*/:
|
|
|
|
break; /* skip whitespace TODO use Unicode */
|
2002-07-12 20:33:01 +00:00
|
|
|
case 0x0021/*! skip java thai modifier reordering*/:
|
|
|
|
break;
|
2001-03-20 00:56:37 +00:00
|
|
|
case 0x002F/*'/'*/:
|
2001-06-02 01:02:26 +00:00
|
|
|
wasInQuote = FALSE; /* if we were copying source characters, we want to stop now */
|
|
|
|
inChars = FALSE; /* we're now processing expansion */
|
2001-03-20 00:56:37 +00:00
|
|
|
break;
|
2001-11-07 03:37:06 +00:00
|
|
|
case 0x005C /* back slash for escaped chars */:
|
|
|
|
isEscaped = TRUE;
|
|
|
|
break;
|
2001-03-20 00:56:37 +00:00
|
|
|
/* found a quote, we're gonna start copying */
|
|
|
|
case 0x0027/*'\''*/:
|
2001-06-02 01:02:26 +00:00
|
|
|
if (newStrength == UCOL_TOK_UNSET) { /* quote is illegal until we have a strength */
|
2002-07-12 20:33:01 +00:00
|
|
|
/*
|
|
|
|
enabling rules to start with a non-token character a < b
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-06-02 01:02:26 +00:00
|
|
|
return NULL;
|
2002-07-12 20:33:01 +00:00
|
|
|
*/
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
2001-06-02 01:02:26 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
inQuote = TRUE;
|
|
|
|
|
2001-06-02 01:02:26 +00:00
|
|
|
if(inChars) { /* we're doing characters */
|
|
|
|
if(wasInQuote == FALSE) {
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->extraCurrent - src->source);
|
2001-06-02 01:02:26 +00:00
|
|
|
}
|
|
|
|
if (newCharsLen != 0) {
|
|
|
|
uprv_memcpy(src->extraCurrent, src->current - newCharsLen, newCharsLen*sizeof(UChar));
|
|
|
|
src->extraCurrent += newCharsLen;
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
newCharsLen++;
|
2001-06-02 01:02:26 +00:00
|
|
|
} else { /* we're doing an expansion */
|
|
|
|
if(wasInQuote == FALSE) {
|
2002-05-22 23:56:30 +00:00
|
|
|
extensionOffset = (uint32_t)(src->extraCurrent - src->source);
|
2001-06-02 01:02:26 +00:00
|
|
|
}
|
|
|
|
if (newExtensionLen != 0) {
|
2001-03-20 00:56:37 +00:00
|
|
|
uprv_memcpy(src->extraCurrent, src->current - newExtensionLen, newExtensionLen*sizeof(UChar));
|
|
|
|
src->extraCurrent += newExtensionLen;
|
|
|
|
}
|
|
|
|
newExtensionLen++;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-06-02 01:02:26 +00:00
|
|
|
wasInQuote = TRUE;
|
|
|
|
|
|
|
|
ch = *(++(src->current));
|
|
|
|
if(ch == 0x0027) { /* copy the double quote */
|
2001-03-21 00:22:35 +00:00
|
|
|
*src->extraCurrent++ = ch;
|
|
|
|
inQuote = FALSE;
|
|
|
|
}
|
2001-03-20 00:56:37 +00:00
|
|
|
break;
|
2001-02-26 10:28:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
/* '@' is french only if the strength is not currently set */
|
|
|
|
/* if it is, it's just a regular character in collation rules */
|
|
|
|
case 0x0040/*'@'*/:
|
|
|
|
if (newStrength == UCOL_TOK_UNSET) {
|
2001-03-30 00:23:46 +00:00
|
|
|
src->opts->frenchCollation = UCOL_ON;
|
2001-03-20 00:56:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-09-27 23:18:14 +00:00
|
|
|
case 0x007C /*|*/: /* this means we have actually been reading prefix part */
|
|
|
|
// we want to store read characters to the prefix part and continue reading
|
|
|
|
// the characters (proper way would be to restart reading the chars, but in
|
|
|
|
// that case we would have to complicate the token hasher, which I do not
|
|
|
|
// intend to play with. Instead, we will do prefixes when prefixes are due
|
|
|
|
// (before adding the elements).
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.prefixOffset = charsOffset;
|
|
|
|
src->parsedToken.prefixLen = newCharsLen;
|
2001-09-27 23:18:14 +00:00
|
|
|
|
|
|
|
if(inChars) { /* we're doing characters */
|
|
|
|
if(wasInQuote == FALSE) {
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->extraCurrent - src->source);
|
2001-09-27 23:18:14 +00:00
|
|
|
}
|
|
|
|
if (newCharsLen != 0) {
|
|
|
|
uprv_memcpy(src->extraCurrent, src->current - newCharsLen, newCharsLen*sizeof(UChar));
|
|
|
|
src->extraCurrent += newCharsLen;
|
|
|
|
}
|
|
|
|
newCharsLen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
wasInQuote = TRUE;
|
|
|
|
|
|
|
|
ch = *(++(src->current));
|
|
|
|
break;
|
|
|
|
|
|
|
|
//charsOffset = 0;
|
|
|
|
//newCharsLen = 0;
|
|
|
|
//break; // We want to store the whole prefix/character sequence. If we break
|
|
|
|
// the '|' is going to get lost.
|
2001-03-20 00:56:37 +00:00
|
|
|
default:
|
|
|
|
if (newStrength == UCOL_TOK_UNSET) {
|
2002-07-12 20:33:01 +00:00
|
|
|
/* enabling rules to start with non-tokens a < b
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-03-20 00:56:37 +00:00
|
|
|
return NULL;
|
2002-07-12 20:33:01 +00:00
|
|
|
*/
|
|
|
|
newStrength = UCOL_TOK_RESET;
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
if (ucol_tok_isSpecialChar(ch) && (inQuote == FALSE)) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-03-20 00:56:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-05-15 17:36:39 +00:00
|
|
|
if(ch == 0x0000 && src->current+1 == src->end) {
|
|
|
|
break;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
if (inChars) {
|
|
|
|
if(newCharsLen == 0) {
|
2002-05-22 23:56:30 +00:00
|
|
|
charsOffset = (uint32_t)(src->current - src->source);
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
2001-03-20 00:56:37 +00:00
|
|
|
newCharsLen++;
|
|
|
|
} else {
|
|
|
|
if(newExtensionLen == 0) {
|
2002-05-22 23:56:30 +00:00
|
|
|
extensionOffset = (uint32_t)(src->current - src->source);
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
|
|
|
newExtensionLen++;
|
2001-03-14 00:12:46 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
break;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
2001-03-20 00:56:37 +00:00
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
if(wasInQuote) {
|
2001-03-21 00:22:35 +00:00
|
|
|
if(ch != 0x27) {
|
2001-03-20 00:56:37 +00:00
|
|
|
*src->extraCurrent++ = ch;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
2001-10-03 05:58:10 +00:00
|
|
|
if(src->extraCurrent > src->extraEnd) {
|
2001-03-20 00:56:37 +00:00
|
|
|
/* reallocate */
|
2001-06-02 01:02:26 +00:00
|
|
|
UChar *newSrc = (UChar *)uprv_realloc(src->source, (src->extraEnd-src->source)*2*sizeof(UChar));
|
|
|
|
if(newSrc != NULL) {
|
|
|
|
src->current = newSrc + (src->current - src->source);
|
|
|
|
src->extraCurrent = newSrc + (src->extraCurrent - src->source);
|
|
|
|
src->end = newSrc + (src->end - src->source);
|
|
|
|
src->extraEnd = newSrc + (src->extraEnd-src->source)*2;
|
|
|
|
src->sourceCurrent = newSrc + (src->sourceCurrent-src->source);
|
|
|
|
src->source = newSrc;
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
src->current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndOfLoop:
|
|
|
|
wasInQuote = FALSE;
|
|
|
|
if (newStrength == UCOL_TOK_UNSET) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-04-19 17:08:07 +00:00
|
|
|
if (newCharsLen == 0 && top == FALSE) {
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,(int32_t)(src->current-src->source),(int32_t)(src->end-src->source),parseError);
|
2001-03-20 00:56:37 +00:00
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.strength = newStrength;
|
|
|
|
src->parsedToken.charsOffset = charsOffset;
|
|
|
|
src->parsedToken.charsLen = newCharsLen;
|
|
|
|
src->parsedToken.extensionOffset = extensionOffset;
|
|
|
|
src->parsedToken.extensionLen = newExtensionLen;
|
|
|
|
src->parsedToken.flags = (UCOL_TOK_VARIABLE_TOP * (variableTop?1:0)) | (UCOL_TOK_TOP * (top?1:0)) | before;
|
2001-03-20 00:56:37 +00:00
|
|
|
|
|
|
|
return src->current;
|
|
|
|
}
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
/*
|
|
|
|
Processing Description
|
|
|
|
1 Build a ListList. Each list has a header, which contains two lists (positive
|
|
|
|
and negative), a reset token, a baseCE, nextCE, and previousCE. The lists and
|
|
|
|
reset may be null.
|
|
|
|
2 As you process, you keep a LAST pointer that points to the last token you
|
|
|
|
handled.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static UColToken *ucol_tok_initAReset(UColTokenParser *src, UChar *expand, uint32_t *expandNext,
|
|
|
|
UParseError *parseError, UErrorCode *status) {
|
2002-07-02 22:32:14 +00:00
|
|
|
if(src->resultLen == src->listCapacity) {
|
|
|
|
// Unfortunately, this won't work, as we store addresses of lhs in token
|
|
|
|
src->listCapacity *= 2;
|
|
|
|
src->lh = (UColTokListHeader *)uprv_realloc(src->lh, src->listCapacity*sizeof(UColTokListHeader));
|
|
|
|
if(src->lh == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-03-07 18:59:00 +00:00
|
|
|
/* do the reset thing */
|
|
|
|
UColToken *sourceToken = (UColToken *)uprv_malloc(sizeof(UColToken));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (sourceToken == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->rulesToParse = src->source;
|
|
|
|
sourceToken->source = src->parsedToken.charsLen << 24 | src->parsedToken.charsOffset;
|
|
|
|
sourceToken->expansion = src->parsedToken.extensionLen << 24 | src->parsedToken.extensionOffset;
|
|
|
|
|
|
|
|
sourceToken->debugSource = *(src->source + src->parsedToken.charsOffset);
|
|
|
|
sourceToken->debugExpansion = *(src->source + src->parsedToken.extensionOffset);
|
|
|
|
|
|
|
|
if(src->parsedToken.prefixOffset != 0) {
|
|
|
|
// this is a syntax error
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
syntaxError(src->source,src->parsedToken.charsOffset-1,src->parsedToken.charsOffset+src->parsedToken.charsLen,parseError);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
sourceToken->prefix = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sourceToken->polarity = UCOL_TOK_POLARITY_POSITIVE; /* TODO: this should also handle reverse */
|
|
|
|
sourceToken->strength = UCOL_TOK_RESET;
|
|
|
|
sourceToken->next = NULL;
|
|
|
|
sourceToken->previous = NULL;
|
|
|
|
sourceToken->noOfCEs = 0;
|
|
|
|
sourceToken->noOfExpCEs = 0;
|
|
|
|
sourceToken->listHeader = &src->lh[src->resultLen];
|
|
|
|
|
|
|
|
src->lh[src->resultLen].first = NULL;
|
|
|
|
src->lh[src->resultLen].last = NULL;
|
|
|
|
src->lh[src->resultLen].first = NULL;
|
|
|
|
src->lh[src->resultLen].last = NULL;
|
|
|
|
|
|
|
|
src->lh[src->resultLen].reset = sourceToken;
|
|
|
|
|
|
|
|
/*
|
|
|
|
3 Consider each item: relation, source, and expansion: e.g. ...< x / y ...
|
|
|
|
First convert all expansions into normal form. Examples:
|
|
|
|
If "xy" doesn't occur earlier in the list or in the UCA, convert &xy * c *
|
|
|
|
d * ... into &x * c/y * d * ...
|
|
|
|
Note: reset values can never have expansions, although they can cause the
|
|
|
|
very next item to have one. They may be contractions, if they are found
|
|
|
|
earlier in the list.
|
|
|
|
*/
|
|
|
|
if(expand != NULL) {
|
|
|
|
/* check to see if there is an expansion */
|
|
|
|
if(src->parsedToken.charsLen > 1) {
|
|
|
|
uint32_t resetCharsOffset;
|
2002-05-22 23:56:30 +00:00
|
|
|
resetCharsOffset = (uint32_t)(expand - src->source);
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->source = ((resetCharsOffset - src->parsedToken.charsOffset ) << 24) | src->parsedToken.charsOffset;
|
|
|
|
*expandNext = ((src->parsedToken.charsLen + src->parsedToken.charsOffset - resetCharsOffset)<<24) | (resetCharsOffset);
|
|
|
|
} else {
|
|
|
|
*expandNext = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
src->resultLen++;
|
2002-07-02 22:32:14 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
uhash_put(src->tailored, sourceToken, sourceToken, status);
|
|
|
|
|
|
|
|
return sourceToken;
|
|
|
|
}
|
|
|
|
|
2001-10-22 05:30:22 +00:00
|
|
|
static
|
2002-03-07 18:59:00 +00:00
|
|
|
inline UColToken *getVirginBefore(UColTokenParser *src, UColToken *sourceToken, uint8_t strength, UParseError *parseError, UErrorCode *status) {
|
2001-05-29 22:53:07 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2001-10-11 21:19:10 +00:00
|
|
|
return NULL;
|
2001-05-29 22:53:07 +00:00
|
|
|
}
|
|
|
|
/* this is a virgin before - we need to fish the anchor from the UCA */
|
|
|
|
collIterate s;
|
|
|
|
uint32_t baseCE = UCOL_NOT_FOUND, baseContCE = UCOL_NOT_FOUND;
|
|
|
|
uint32_t CE, SecondCE;
|
|
|
|
uint32_t invPos;
|
|
|
|
if(sourceToken != NULL) {
|
2002-07-16 01:46:42 +00:00
|
|
|
uprv_init_collIterate(src->UCA, src->source+((sourceToken->source)&0xFFFFFF), 1, &s);
|
2001-05-29 22:53:07 +00:00
|
|
|
} else {
|
2002-07-16 01:46:42 +00:00
|
|
|
uprv_init_collIterate(src->UCA, src->source+src->parsedToken.charsOffset /**charsOffset*/, 1, &s);
|
2001-05-29 22:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
baseCE = ucol_getNextCE(src->UCA, &s, status) & 0xFFFFFF3F;
|
|
|
|
baseContCE = ucol_getNextCE(src->UCA, &s, status);
|
|
|
|
if(baseContCE == UCOL_NO_MORE_CES) {
|
|
|
|
baseContCE = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
invPos = ucol_inv_getPrevCE(baseCE, baseContCE, &CE, &SecondCE, strength);
|
|
|
|
|
|
|
|
uint32_t *CETable = (uint32_t *)((uint8_t *)src->invUCA+src->invUCA->table);
|
|
|
|
uint32_t ch = CETable[3*invPos+2];
|
|
|
|
|
|
|
|
if((ch & UCOL_INV_SIZEMASK) != 0) {
|
2001-10-03 01:49:25 +00:00
|
|
|
uint16_t *conts = (uint16_t *)((uint8_t *)src->invUCA+src->invUCA->conts);
|
2001-05-29 22:53:07 +00:00
|
|
|
uint32_t offset = (ch & UCOL_INV_OFFSETMASK);
|
|
|
|
ch = conts[offset];
|
|
|
|
}
|
2002-05-22 23:56:30 +00:00
|
|
|
*src->extraCurrent++ = (UChar)ch;
|
|
|
|
src->parsedToken.charsOffset = (uint32_t)(src->extraCurrent - src->source - 1);
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.charsLen = 1;
|
2001-10-03 19:51:31 +00:00
|
|
|
|
|
|
|
// We got an UCA before. However, this might have been tailored.
|
|
|
|
// example:
|
|
|
|
// &\u30ca = \u306a
|
|
|
|
// &[before 3]\u306a<<<\u306a|\u309d
|
|
|
|
|
2001-10-17 22:57:15 +00:00
|
|
|
|
|
|
|
// uint32_t key = (*newCharsLen << 24) | *charsOffset;
|
|
|
|
UColToken key;
|
2002-03-07 18:59:00 +00:00
|
|
|
uint32_t expandNext = 0;
|
|
|
|
key.source = (src->parsedToken.charsLen/**newCharsLen*/ << 24) | src->parsedToken.charsOffset/**charsOffset*/;
|
2001-10-17 22:57:15 +00:00
|
|
|
key.rulesToParse = src->source;
|
2001-10-03 19:51:31 +00:00
|
|
|
|
2001-10-17 22:57:15 +00:00
|
|
|
//sourceToken = (UColToken *)uhash_iget(src->tailored, (int32_t)key);
|
|
|
|
sourceToken = (UColToken *)uhash_get(src->tailored, &key);
|
2001-10-03 19:51:31 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
// if we found a tailored thing, we have to use the UCA value and construct
|
|
|
|
// a new reset token with constructed name
|
|
|
|
if(sourceToken != NULL && sourceToken->strength != UCOL_TOK_RESET) {
|
|
|
|
// character to which we want to anchor is already tailored.
|
|
|
|
// We need to construct a new token which will be the anchor
|
|
|
|
// point
|
2002-03-15 23:41:56 +00:00
|
|
|
*(src->extraCurrent-1) = 0xFFFE;
|
|
|
|
*src->extraCurrent++ = (UChar)ch;
|
|
|
|
src->parsedToken.charsLen++;
|
2002-03-07 18:59:00 +00:00
|
|
|
src->lh[src->resultLen].baseCE = CE & 0xFFFFFF3F;
|
|
|
|
if(isContinuation(SecondCE)) {
|
|
|
|
src->lh[src->resultLen].baseContCE = SecondCE;
|
|
|
|
} else {
|
|
|
|
src->lh[src->resultLen].baseContCE = 0;
|
|
|
|
}
|
2002-03-15 23:41:56 +00:00
|
|
|
src->lh[src->resultLen].nextCE = 0;
|
|
|
|
src->lh[src->resultLen].nextContCE = 0;
|
|
|
|
src->lh[src->resultLen].previousCE = 0;
|
|
|
|
src->lh[src->resultLen].previousContCE = 0;
|
|
|
|
|
|
|
|
src->lh[src->resultLen].indirect = FALSE;
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken = ucol_tok_initAReset(src, 0, &expandNext, parseError, status);
|
|
|
|
}
|
2001-10-03 19:51:31 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
return sourceToken;
|
2001-10-03 19:51:31 +00:00
|
|
|
|
2001-05-29 22:53:07 +00:00
|
|
|
}
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
uint32_t ucol_tok_assembleTokenList(UColTokenParser *src, UParseError *parseError, UErrorCode *status) {
|
2001-03-20 00:56:37 +00:00
|
|
|
UColToken *lastToken = NULL;
|
|
|
|
const UChar *parseEnd = NULL;
|
|
|
|
uint32_t expandNext = 0;
|
|
|
|
UBool variableTop = FALSE;
|
|
|
|
UBool top = FALSE;
|
2002-03-15 23:41:56 +00:00
|
|
|
uint16_t specs = 0;
|
2001-03-20 00:56:37 +00:00
|
|
|
UColTokListHeader *ListList = NULL;
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.strength = UCOL_TOK_UNSET;
|
2001-03-20 00:56:37 +00:00
|
|
|
|
|
|
|
ListList = src->lh;
|
|
|
|
|
2002-07-18 00:45:20 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
while(src->current < src->end) {
|
2002-03-07 18:59:00 +00:00
|
|
|
src->parsedToken.prefixOffset = 0;
|
2001-03-20 00:56:37 +00:00
|
|
|
|
2001-06-06 20:21:48 +00:00
|
|
|
parseEnd = ucol_tok_parseNextToken(src,
|
|
|
|
(UBool)(lastToken == NULL),
|
2001-08-16 00:55:16 +00:00
|
|
|
parseError,
|
2001-06-06 20:21:48 +00:00
|
|
|
status);
|
2001-03-20 00:56:37 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
specs = src->parsedToken.flags;
|
|
|
|
|
|
|
|
|
2001-06-06 20:21:48 +00:00
|
|
|
variableTop = ((specs & UCOL_TOK_VARIABLE_TOP) != 0);
|
|
|
|
top = ((specs & UCOL_TOK_TOP) != 0);
|
2001-05-02 05:05:06 +00:00
|
|
|
|
2001-03-20 00:56:37 +00:00
|
|
|
if(U_SUCCESS(*status) && parseEnd != NULL) {
|
2001-01-31 07:20:56 +00:00
|
|
|
UColToken *sourceToken = NULL;
|
2001-10-17 22:57:15 +00:00
|
|
|
//uint32_t key = 0;
|
2001-05-18 23:48:16 +00:00
|
|
|
uint32_t lastStrength = UCOL_TOK_UNSET;
|
|
|
|
|
|
|
|
if(lastToken != NULL ) {
|
|
|
|
lastStrength = lastToken->strength;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-10-17 22:57:15 +00:00
|
|
|
//key = newCharsLen << 24 | charsOffset;
|
|
|
|
UColToken key;
|
2002-03-07 18:59:00 +00:00
|
|
|
key.source = src->parsedToken.charsLen << 24 | src->parsedToken.charsOffset;
|
2001-10-17 22:57:15 +00:00
|
|
|
key.rulesToParse = src->source;
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-06-06 20:21:48 +00:00
|
|
|
/* 4 Lookup each source in the CharsToToken map, and find a sourceToken */
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken = (UColToken *)uhash_get(src->tailored, &key);
|
2001-01-31 21:10:55 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
if(src->parsedToken.strength != UCOL_TOK_RESET) {
|
2001-01-31 20:17:12 +00:00
|
|
|
if(lastToken == NULL) { /* this means that rules haven't started properly */
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2002-05-22 23:56:30 +00:00
|
|
|
syntaxError(src->source,0,(int32_t)(src->end-src->source),parseError);
|
2001-01-31 20:17:12 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
/* 6 Otherwise (when relation != reset) */
|
|
|
|
if(sourceToken == NULL) {
|
|
|
|
/* If sourceToken is null, create new one, */
|
|
|
|
sourceToken = (UColToken *)uprv_malloc(sizeof(UColToken));
|
2002-07-02 15:10:30 +00:00
|
|
|
/* test for NULL */
|
2002-06-29 09:31:05 +00:00
|
|
|
if (sourceToken == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
2001-10-17 22:57:15 +00:00
|
|
|
sourceToken->rulesToParse = src->source;
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->source = src->parsedToken.charsLen << 24 | src->parsedToken.charsOffset;
|
2001-01-31 21:10:55 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->debugSource = *(src->source + src->parsedToken.charsOffset);
|
2001-01-31 21:10:55 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->prefix = src->parsedToken.prefixLen << 24 | src->parsedToken.prefixOffset;
|
|
|
|
sourceToken->debugPrefix = *(src->source + src->parsedToken.prefixOffset);
|
2001-09-27 23:18:14 +00:00
|
|
|
|
2001-01-31 23:12:37 +00:00
|
|
|
sourceToken->polarity = UCOL_TOK_POLARITY_POSITIVE; /* TODO: this should also handle reverse */
|
2001-01-31 07:20:56 +00:00
|
|
|
sourceToken->next = NULL;
|
|
|
|
sourceToken->previous = NULL;
|
2001-02-26 10:28:56 +00:00
|
|
|
sourceToken->noOfCEs = 0;
|
|
|
|
sourceToken->noOfExpCEs = 0;
|
2002-03-07 18:59:00 +00:00
|
|
|
uhash_put(src->tailored, sourceToken, sourceToken, status);
|
2001-01-31 07:20:56 +00:00
|
|
|
} else {
|
|
|
|
/* we could have fished out a reset here */
|
2001-06-06 20:21:48 +00:00
|
|
|
if(sourceToken->strength != UCOL_TOK_RESET && lastToken != sourceToken) {
|
2001-01-31 07:20:56 +00:00
|
|
|
/* otherwise remove sourceToken from where it was. */
|
|
|
|
if(sourceToken->next != NULL) {
|
2001-05-18 23:48:16 +00:00
|
|
|
if(sourceToken->next->strength > sourceToken->strength) {
|
|
|
|
sourceToken->next->strength = sourceToken->strength;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
sourceToken->next->previous = sourceToken->previous;
|
|
|
|
} else {
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->listHeader->last = sourceToken->previous;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sourceToken->previous != NULL) {
|
|
|
|
sourceToken->previous->next = sourceToken->next;
|
|
|
|
} else {
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->listHeader->first = sourceToken->next;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->next = NULL;
|
|
|
|
sourceToken->previous = NULL;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->strength = src->parsedToken.strength;
|
2001-01-31 23:12:37 +00:00
|
|
|
sourceToken->listHeader = lastToken->listHeader;
|
2001-04-19 17:08:07 +00:00
|
|
|
|
2001-01-31 23:12:37 +00:00
|
|
|
/*
|
2002-02-28 01:42:40 +00:00
|
|
|
1. Find the strongest strength in each list, and set strongestP and strongestN
|
2001-01-31 23:12:37 +00:00
|
|
|
accordingly in the headers.
|
|
|
|
*/
|
2001-05-19 02:37:47 +00:00
|
|
|
if(lastStrength == UCOL_TOK_RESET
|
2001-06-06 20:21:48 +00:00
|
|
|
|| sourceToken->listHeader->first == 0) {
|
2001-01-31 07:20:56 +00:00
|
|
|
/* If LAST is a reset
|
2001-05-18 23:48:16 +00:00
|
|
|
insert sourceToken in the list. */
|
2001-06-06 20:21:48 +00:00
|
|
|
if(sourceToken->listHeader->first == 0) {
|
|
|
|
sourceToken->listHeader->first = sourceToken;
|
|
|
|
sourceToken->listHeader->last = sourceToken;
|
2001-05-18 23:48:16 +00:00
|
|
|
} else { /* we need to find a place for us */
|
|
|
|
/* and we'll get in front of the same strength */
|
2001-06-06 20:21:48 +00:00
|
|
|
if(sourceToken->listHeader->first->strength <= sourceToken->strength) {
|
|
|
|
sourceToken->next = sourceToken->listHeader->first;
|
2001-05-18 23:48:16 +00:00
|
|
|
sourceToken->next->previous = sourceToken;
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->listHeader->first = sourceToken;
|
2001-05-18 23:48:16 +00:00
|
|
|
sourceToken->previous = NULL;
|
|
|
|
} else {
|
2001-06-06 20:21:48 +00:00
|
|
|
lastToken = sourceToken->listHeader->first;
|
2001-05-18 23:48:16 +00:00
|
|
|
while(lastToken->next != NULL && lastToken->next->strength > sourceToken->strength) {
|
|
|
|
lastToken = lastToken->next;
|
|
|
|
}
|
|
|
|
if(lastToken->next != NULL) {
|
|
|
|
lastToken->next->previous = sourceToken;
|
|
|
|
} else {
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->listHeader->last = sourceToken;
|
2001-05-18 23:48:16 +00:00
|
|
|
}
|
|
|
|
sourceToken->previous = lastToken;
|
|
|
|
sourceToken->next = lastToken->next;
|
|
|
|
lastToken->next = sourceToken;
|
|
|
|
}
|
2001-01-31 23:12:37 +00:00
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
} else {
|
|
|
|
/* Otherwise (when LAST is not a reset)
|
|
|
|
if polarity (LAST) == polarity(relation), insert sourceToken after LAST,
|
|
|
|
otherwise insert before.
|
|
|
|
when inserting after or before, search to the next position with the same
|
|
|
|
strength in that direction. (This is called postpone insertion). */
|
2001-05-18 23:48:16 +00:00
|
|
|
if(sourceToken != lastToken) {
|
|
|
|
if(lastToken->polarity == sourceToken->polarity) {
|
|
|
|
while(lastToken->next != NULL && lastToken->next->strength > sourceToken->strength) {
|
|
|
|
lastToken = lastToken->next;
|
|
|
|
}
|
|
|
|
sourceToken->previous = lastToken;
|
|
|
|
if(lastToken->next != NULL) {
|
|
|
|
lastToken->next->previous = sourceToken;
|
|
|
|
} else {
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->listHeader->last = sourceToken;
|
2001-05-18 23:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sourceToken->next = lastToken->next;
|
|
|
|
lastToken->next = sourceToken;
|
2001-01-31 07:20:56 +00:00
|
|
|
} else {
|
2001-05-18 23:48:16 +00:00
|
|
|
while(lastToken->previous != NULL && lastToken->previous->strength > sourceToken->strength) {
|
|
|
|
lastToken = lastToken->previous;
|
|
|
|
}
|
|
|
|
sourceToken->next = lastToken;
|
|
|
|
if(lastToken->previous != NULL) {
|
|
|
|
lastToken->previous->next = sourceToken;
|
|
|
|
} else {
|
2001-06-06 20:21:48 +00:00
|
|
|
sourceToken->listHeader->first = sourceToken;
|
2001-05-18 23:48:16 +00:00
|
|
|
}
|
|
|
|
sourceToken->previous = lastToken->previous;
|
|
|
|
lastToken->previous = sourceToken;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
2001-05-18 23:48:16 +00:00
|
|
|
} else { /* repeated one thing twice in rules, stay with the stronger strength */
|
|
|
|
if(lastStrength < sourceToken->strength) {
|
|
|
|
sourceToken->strength = lastStrength;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-06-06 20:21:48 +00:00
|
|
|
|
|
|
|
/* if the token was a variable top, we're gonna put it in */
|
|
|
|
if(variableTop == TRUE && src->varTop == NULL) {
|
|
|
|
variableTop = FALSE;
|
|
|
|
src->varTop = sourceToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Treat the expansions.
|
|
|
|
// There are two types of expansions: explicit (x / y) and reset based propagating expansions
|
|
|
|
// (&abc * d * e <=> &ab * d / c * e / c)
|
|
|
|
// if both of them are in effect for a token, they are combined.
|
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->expansion = src->parsedToken.extensionLen << 24 | src->parsedToken.extensionOffset;
|
2001-06-06 20:21:48 +00:00
|
|
|
|
|
|
|
if(expandNext != 0) {
|
|
|
|
if(sourceToken->strength == UCOL_PRIMARY) { /* primary strength kills off the implicit expansion */
|
|
|
|
expandNext = 0;
|
|
|
|
} else if(sourceToken->expansion == 0) { /* if there is no expansion, implicit is just added to the token */
|
|
|
|
sourceToken->expansion = expandNext;
|
|
|
|
} else { /* there is both explicit and implicit expansion. We need to make a combination */
|
|
|
|
memcpy(src->extraCurrent, src->source + (expandNext & 0xFFFFFF), (expandNext >> 24)*sizeof(UChar));
|
2002-03-07 18:59:00 +00:00
|
|
|
memcpy(src->extraCurrent+(expandNext >> 24), src->source + src->parsedToken.extensionOffset, src->parsedToken.extensionLen*sizeof(UChar));
|
2002-05-22 23:56:30 +00:00
|
|
|
sourceToken->expansion = (uint32_t)(((expandNext >> 24) + src->parsedToken.extensionLen)<<24 | (src->extraCurrent - src->source));
|
2002-03-07 18:59:00 +00:00
|
|
|
src->extraCurrent += (expandNext >> 24) + src->parsedToken.extensionLen;
|
2001-06-06 20:21:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is just for debugging purposes
|
|
|
|
if(sourceToken->expansion != 0) {
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken->debugExpansion = *(src->source + src->parsedToken.extensionOffset);
|
2001-06-06 20:21:48 +00:00
|
|
|
} else {
|
|
|
|
sourceToken->debugExpansion = 0;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
} else {
|
2002-03-26 16:46:17 +00:00
|
|
|
if(lastToken != NULL && lastStrength == UCOL_TOK_RESET) {
|
|
|
|
/* if the previous token was also a reset, */
|
|
|
|
/*this means that we have two consecutive resets */
|
|
|
|
/* and we want to remove the previous one if empty*/
|
|
|
|
if(ListList[src->resultLen-1].first == NULL) {
|
|
|
|
src->resultLen--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-05 22:52:56 +00:00
|
|
|
if(sourceToken == NULL) { /* this is a reset, but it might still be somewhere in the tailoring, in shorter form */
|
2002-03-07 18:59:00 +00:00
|
|
|
uint32_t searchCharsLen = src->parsedToken.charsLen;
|
2001-06-05 22:52:56 +00:00
|
|
|
while(searchCharsLen > 1 && sourceToken == NULL) {
|
|
|
|
searchCharsLen--;
|
2001-10-17 22:57:15 +00:00
|
|
|
//key = searchCharsLen << 24 | charsOffset;
|
|
|
|
UColToken key;
|
2002-03-07 18:59:00 +00:00
|
|
|
key.source = searchCharsLen << 24 | src->parsedToken.charsOffset;
|
2001-10-17 22:57:15 +00:00
|
|
|
key.rulesToParse = src->source;
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken = (UColToken *)uhash_get(src->tailored, &key);
|
2001-06-05 22:52:56 +00:00
|
|
|
}
|
|
|
|
if(sourceToken != NULL) {
|
2002-03-07 18:59:00 +00:00
|
|
|
expandNext = (src->parsedToken.charsLen - searchCharsLen) << 24 | (src->parsedToken.charsOffset + searchCharsLen);
|
2001-06-05 22:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-11 22:43:49 +00:00
|
|
|
if((specs & UCOL_TOK_BEFORE) != 0) { /* we're doing before */
|
|
|
|
if(top == FALSE) { /* there is no indirection */
|
|
|
|
uint8_t strength = (specs & UCOL_TOK_BEFORE) - 1;
|
|
|
|
if(sourceToken != NULL && sourceToken->strength != UCOL_TOK_RESET) {
|
|
|
|
/* this is a before that is already ordered in the UCA - so we need to get the previous with good strength */
|
|
|
|
while(sourceToken->strength > strength && sourceToken->previous != NULL) {
|
2001-05-18 23:48:16 +00:00
|
|
|
sourceToken = sourceToken->previous;
|
2002-07-11 22:43:49 +00:00
|
|
|
}
|
|
|
|
/* here, either we hit the strength or NULL */
|
|
|
|
if(sourceToken->strength == strength) {
|
|
|
|
if(sourceToken->previous != NULL) {
|
|
|
|
sourceToken = sourceToken->previous;
|
|
|
|
} else { /* start of list */
|
|
|
|
sourceToken = sourceToken->listHeader->reset;
|
|
|
|
}
|
|
|
|
} else { /* we hit NULL */
|
|
|
|
/* we should be doing the else part */
|
2001-05-18 23:48:16 +00:00
|
|
|
sourceToken = sourceToken->listHeader->reset;
|
2002-07-11 22:43:49 +00:00
|
|
|
sourceToken = getVirginBefore(src, sourceToken, strength, parseError, status);
|
|
|
|
}
|
|
|
|
} else {
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken = getVirginBefore(src, sourceToken, strength, parseError, status);
|
2001-05-18 23:48:16 +00:00
|
|
|
}
|
2002-07-11 22:43:49 +00:00
|
|
|
} else { /* this is both before and indirection */
|
|
|
|
top = FALSE;
|
|
|
|
ListList[src->resultLen].previousCE = 0;
|
|
|
|
ListList[src->resultLen].previousContCE = 0;
|
|
|
|
ListList[src->resultLen].indirect = TRUE;
|
|
|
|
/* we need to do slightly more work. we need to get the baseCE using the */
|
|
|
|
/* inverse UCA & getPrevious. The next bound is not set, and will be decided */
|
|
|
|
/* in ucol_bld */
|
|
|
|
uint8_t strength = (specs & UCOL_TOK_BEFORE) - 1;
|
|
|
|
uint32_t baseCE = ucolIndirectBoundaries[src->parsedToken.indirectIndex].startCE;
|
|
|
|
uint32_t baseContCE = ucolIndirectBoundaries[src->parsedToken.indirectIndex].startContCE;//&0xFFFFFF3F;
|
|
|
|
uint32_t CE = UCOL_NOT_FOUND, SecondCE = UCOL_NOT_FOUND;
|
|
|
|
|
|
|
|
/*int32_t invPos = ucol_inv_getPrevCE(baseCE, baseContCE, &CE, &SecondCE, strength);*/
|
|
|
|
ucol_inv_getPrevCE(baseCE, baseContCE, &CE, &SecondCE, strength);
|
|
|
|
|
|
|
|
ListList[src->resultLen].baseCE = CE;
|
|
|
|
ListList[src->resultLen].baseContCE = SecondCE;
|
|
|
|
ListList[src->resultLen].nextCE = 0;
|
|
|
|
ListList[src->resultLen].nextContCE = 0;
|
|
|
|
|
|
|
|
sourceToken = ucol_tok_initAReset(src, 0, &expandNext, parseError, status);
|
2001-05-18 23:48:16 +00:00
|
|
|
}
|
2001-05-02 05:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-31 07:20:56 +00:00
|
|
|
/* 5 If the relation is a reset:
|
|
|
|
If sourceToken is null
|
|
|
|
Create new list, create new sourceToken, make the baseCE from source, put
|
|
|
|
the sourceToken in ListHeader of the new list */
|
|
|
|
if(sourceToken == NULL) {
|
2001-01-31 20:17:12 +00:00
|
|
|
/*
|
|
|
|
3 Consider each item: relation, source, and expansion: e.g. ...< x / y ...
|
|
|
|
First convert all expansions into normal form. Examples:
|
|
|
|
If "xy" doesn't occur earlier in the list or in the UCA, convert &xy * c *
|
|
|
|
d * ... into &x * c/y * d * ...
|
|
|
|
Note: reset values can never have expansions, although they can cause the
|
|
|
|
very next item to have one. They may be contractions, if they are found
|
|
|
|
earlier in the list.
|
|
|
|
*/
|
2001-03-07 19:43:06 +00:00
|
|
|
if(top == FALSE) {
|
2002-03-07 18:59:00 +00:00
|
|
|
collIterate s;
|
|
|
|
uint32_t CE = UCOL_NOT_FOUND, SecondCE = UCOL_NOT_FOUND;
|
2001-01-31 20:17:12 +00:00
|
|
|
|
2002-07-16 01:46:42 +00:00
|
|
|
uprv_init_collIterate(src->UCA, src->source+src->parsedToken.charsOffset, src->parsedToken.charsLen, &s);
|
2001-01-31 07:20:56 +00:00
|
|
|
|
2001-03-07 19:43:06 +00:00
|
|
|
CE = ucol_getNextCE(src->UCA, &s, status);
|
2002-03-07 18:59:00 +00:00
|
|
|
UChar *expand = s.pos;
|
2001-03-07 19:43:06 +00:00
|
|
|
SecondCE = ucol_getNextCE(src->UCA, &s, status);
|
2002-03-07 18:59:00 +00:00
|
|
|
|
2001-05-10 22:33:50 +00:00
|
|
|
ListList[src->resultLen].baseCE = CE & 0xFFFFFF3F;
|
2001-03-07 19:43:06 +00:00
|
|
|
if(isContinuation(SecondCE)) {
|
|
|
|
ListList[src->resultLen].baseContCE = SecondCE;
|
|
|
|
} else {
|
|
|
|
ListList[src->resultLen].baseContCE = 0;
|
|
|
|
}
|
2002-03-15 23:41:56 +00:00
|
|
|
ListList[src->resultLen].nextCE = 0;
|
|
|
|
ListList[src->resultLen].nextContCE = 0;
|
|
|
|
ListList[src->resultLen].previousCE = 0;
|
|
|
|
ListList[src->resultLen].previousContCE = 0;
|
|
|
|
ListList[src->resultLen].indirect = FALSE;
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken = ucol_tok_initAReset(src, expand, &expandNext, parseError, status);
|
2001-03-07 19:43:06 +00:00
|
|
|
} else { /* top == TRUE */
|
2002-07-11 22:43:49 +00:00
|
|
|
/* just use the supplied values */
|
2001-03-07 19:43:06 +00:00
|
|
|
top = FALSE;
|
2002-03-15 23:41:56 +00:00
|
|
|
ListList[src->resultLen].previousCE = 0;
|
|
|
|
ListList[src->resultLen].previousContCE = 0;
|
|
|
|
ListList[src->resultLen].indirect = TRUE;
|
2002-07-11 22:43:49 +00:00
|
|
|
ListList[src->resultLen].baseCE = ucolIndirectBoundaries[src->parsedToken.indirectIndex].startCE;
|
|
|
|
ListList[src->resultLen].baseContCE = ucolIndirectBoundaries[src->parsedToken.indirectIndex].startContCE;
|
|
|
|
ListList[src->resultLen].nextCE = ucolIndirectBoundaries[src->parsedToken.indirectIndex].limitCE;
|
|
|
|
ListList[src->resultLen].nextContCE = ucolIndirectBoundaries[src->parsedToken.indirectIndex].limitContCE;
|
2002-03-15 23:41:56 +00:00
|
|
|
|
2002-03-07 18:59:00 +00:00
|
|
|
sourceToken = ucol_tok_initAReset(src, 0, &expandNext, parseError, status);
|
2002-03-15 23:41:56 +00:00
|
|
|
|
2001-02-08 01:04:43 +00:00
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
} else { /* reset to something already in rules */
|
2001-03-14 00:12:46 +00:00
|
|
|
top = FALSE;
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 7 After all this, set LAST to point to sourceToken, and goto step 3. */
|
|
|
|
lastToken = sourceToken;
|
2001-03-20 00:56:37 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2001-01-31 07:20:56 +00:00
|
|
|
}
|
|
|
|
|
2001-06-06 20:21:48 +00:00
|
|
|
if(src->resultLen > 0 && ListList[src->resultLen-1].first == NULL) {
|
2001-04-05 21:27:44 +00:00
|
|
|
src->resultLen--;
|
|
|
|
}
|
2001-02-28 21:50:23 +00:00
|
|
|
return src->resultLen;
|
2001-01-29 22:09:24 +00:00
|
|
|
}
|
|
|
|
|
2001-02-28 19:01:23 +00:00
|
|
|
|
2001-02-28 21:50:23 +00:00
|
|
|
void ucol_tok_closeTokenList(UColTokenParser *src) {
|
2001-06-06 20:21:48 +00:00
|
|
|
if(src->tailored != NULL) {
|
|
|
|
uhash_close(src->tailored);
|
2001-05-31 06:04:56 +00:00
|
|
|
}
|
|
|
|
if(src->lh != NULL) {
|
|
|
|
uprv_free(src->lh);
|
|
|
|
}
|
|
|
|
if(src->source != NULL) {
|
|
|
|
uprv_free(src->source);
|
|
|
|
}
|
2001-06-06 22:13:37 +00:00
|
|
|
if(src->opts != NULL) {
|
|
|
|
uprv_free(src->opts);
|
|
|
|
}
|
2001-02-28 21:50:23 +00:00
|
|
|
}
|
2001-03-06 00:57:48 +00:00
|
|
|
|