-static void
-_set_addAll(USet *set, const UChar *s, int32_t length) {
- UChar32 c;
- int32_t i;
-
- /* needs length>=0 */
- for(i=0; i<length; /* U16_NEXT advances i */) {
- U16_NEXT(s, i, length, c);
- uset_add(set, c);
- }
-}
-
-/* parser for BidiMirroring.txt --------------------------------------------- */
-
-#define MAX_MIRROR_COUNT 2000
-
-static uint32_t mirrorMappings[MAX_MIRROR_COUNT][2];
-static int32_t mirrorCount=0;
-
-static void U_CALLCONV
-mirrorLineFn(void *context,
- char *fields[][2], int32_t fieldCount,
- UErrorCode *pErrorCode) {
- char *end;
- static uint32_t prevCode=0;
-
- mirrorMappings[mirrorCount][0]=(uint32_t)uprv_strtoul(fields[0][0], &end, 16);
- if(end<=fields[0][0] || end!=fields[0][1]) {
- fprintf(stderr, "genprops: syntax error in BidiMirroring.txt field 0 at %s\n", fields[0][0]);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
-
- mirrorMappings[mirrorCount][1]=(uint32_t)uprv_strtoul(fields[1][0], &end, 16);
- if(end<=fields[1][0] || end!=fields[1][1]) {
- fprintf(stderr, "genprops: syntax error in BidiMirroring.txt field 1 at %s\n", fields[1][0]);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
-
- /* check that the code points (mirrorMappings[mirrorCount][0]) are in ascending order */
- if(mirrorMappings[mirrorCount][0]<=prevCode && mirrorMappings[mirrorCount][0]>0) {
- fprintf(stderr, "genprops: error - BidiMirroring entries out of order, U+%04lx after U+%04lx\n",
- (unsigned long)mirrorMappings[mirrorCount][0],
- (unsigned long)prevCode);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
- prevCode=mirrorMappings[mirrorCount][0];
-
- if(++mirrorCount==MAX_MIRROR_COUNT) {
- fprintf(stderr, "genprops: too many mirror mappings\n");
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- exit(U_INDEX_OUTOFBOUNDS_ERROR);
- }
-}
-
-static void
-parseBidiMirroring(const char *filename, UErrorCode *pErrorCode) {
- char *fields[2][2];
-
- if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
- return;
- }
-
- u_parseDelimitedFile(filename, ';', fields, 2, mirrorLineFn, NULL, pErrorCode);
-}
-
-/* parser for SpecialCasing.txt --------------------------------------------- */
-
-#define MAX_SPECIAL_CASING_COUNT 500
-
-static SpecialCasing specialCasings[MAX_SPECIAL_CASING_COUNT];
-static int32_t specialCasingCount=0;
-
-static void U_CALLCONV
-specialCasingLineFn(void *context,
- char *fields[][2], int32_t fieldCount,
- UErrorCode *pErrorCode) {
- char *end;
-
- /* get code point */
- specialCasings[specialCasingCount].code=(uint32_t)uprv_strtoul(u_skipWhitespace(fields[0][0]), &end, 16);
- end=(char *)u_skipWhitespace(end);
- if(end<=fields[0][0] || end!=fields[0][1]) {
- fprintf(stderr, "genprops: syntax error in SpecialCasing.txt field 0 at %s\n", fields[0][0]);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
-
- /* is this a complex mapping? */
- if(*(end=(char *)u_skipWhitespace(fields[4][0]))!=0 && *end!=';' && *end!='#') {
- /* there is some condition text in the fifth field */
- specialCasings[specialCasingCount].isComplex=TRUE;
-
- /* do not store any actual mappings for this */
- specialCasings[specialCasingCount].lowerCase[0]=0;
- specialCasings[specialCasingCount].upperCase[0]=0;
- specialCasings[specialCasingCount].titleCase[0]=0;
- } else {
- /* just set the "complex" flag and get the case mappings */
- specialCasings[specialCasingCount].isComplex=FALSE;
- specialCasings[specialCasingCount].lowerCase[0]=
- (UChar)u_parseString(fields[1][0], specialCasings[specialCasingCount].lowerCase+1, 31, NULL, pErrorCode);
- specialCasings[specialCasingCount].upperCase[0]=
- (UChar)u_parseString(fields[3][0], specialCasings[specialCasingCount].upperCase+1, 31, NULL, pErrorCode);
- specialCasings[specialCasingCount].titleCase[0]=
- (UChar)u_parseString(fields[2][0], specialCasings[specialCasingCount].titleCase+1, 31, NULL, pErrorCode);
- if(U_FAILURE(*pErrorCode)) {
- fprintf(stderr, "genprops: error parsing special casing at %s\n", fields[0][0]);
- exit(*pErrorCode);
- }
-
- uset_add(caseSensitive, (UChar32)specialCasings[specialCasingCount].code);
- _set_addAll(caseSensitive, specialCasings[specialCasingCount].lowerCase+1, specialCasings[specialCasingCount].lowerCase[0]);
- _set_addAll(caseSensitive, specialCasings[specialCasingCount].upperCase+1, specialCasings[specialCasingCount].upperCase[0]);
- _set_addAll(caseSensitive, specialCasings[specialCasingCount].titleCase+1, specialCasings[specialCasingCount].titleCase[0]);
- }
-
- if(++specialCasingCount==MAX_SPECIAL_CASING_COUNT) {
- fprintf(stderr, "genprops: too many special casing mappings\n");
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- exit(U_INDEX_OUTOFBOUNDS_ERROR);
- }
-}
-
-static int
-compareSpecialCasings(const void *left, const void *right) {
- return ((const SpecialCasing *)left)->code-((const SpecialCasing *)right)->code;
-}
-
-static void
-parseSpecialCasing(const char *filename, UErrorCode *pErrorCode) {
- char *fields[5][2];
- int32_t i, j;
-
- if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
- return;
- }
-
- u_parseDelimitedFile(filename, ';', fields, 5, specialCasingLineFn, NULL, pErrorCode);
-
- /* sort the special casing entries by code point */
- if(specialCasingCount>0) {
- qsort(specialCasings, specialCasingCount, sizeof(SpecialCasing), compareSpecialCasings);
- }
-
- /* replace multiple entries for any code point by one "complex" one */
- j=0;
- for(i=1; i<specialCasingCount; ++i) {
- if(specialCasings[i-1].code==specialCasings[i].code) {
- /* there is a duplicate code point */
- specialCasings[i-1].code=0x7fffffff; /* remove this entry in the following qsort */
- specialCasings[i].isComplex=TRUE; /* make the following one complex */
- specialCasings[i].lowerCase[0]=0;
- specialCasings[i].upperCase[0]=0;
- specialCasings[i].titleCase[0]=0;
- ++j;
- }
- }
-
- /* if some entries just were removed, then re-sort */
- if(j>0) {
- qsort(specialCasings, specialCasingCount, sizeof(SpecialCasing), compareSpecialCasings);
- specialCasingCount-=j;
- }
-
- /*
- * Add one complex mapping to caseSensitive that was filtered out above:
- * Greek final Sigma has a conditional mapping but not locale-sensitive,
- * and it is taken when lowercasing just U+03A3 alone.
- * 03A3; 03C2; 03A3; 03A3; Final_Sigma; # GREEK CAPITAL LETTER SIGMA
- */
- uset_add(caseSensitive, 0x3c2);
-}
-
-/* parser for CaseFolding.txt ----------------------------------------------- */
-
-#define MAX_CASE_FOLDING_COUNT 2000
-
-static CaseFolding caseFoldings[MAX_CASE_FOLDING_COUNT];
-static int32_t caseFoldingCount=0;
-
-static void U_CALLCONV
-caseFoldingLineFn(void *context,
- char *fields[][2], int32_t fieldCount,
- UErrorCode *pErrorCode) {
- char *end;
- static uint32_t prevCode=0;
- int32_t count;
- char status;
-
- /* get code point */
- caseFoldings[caseFoldingCount].code=(uint32_t)uprv_strtoul(u_skipWhitespace(fields[0][0]), &end, 16);
- end=(char *)u_skipWhitespace(end);
- if(end<=fields[0][0] || end!=fields[0][1]) {
- fprintf(stderr, "genprops: syntax error in CaseFolding.txt field 0 at %s\n", fields[0][0]);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
-
- /* get the status of this mapping */
- caseFoldings[caseFoldingCount].status=status=*u_skipWhitespace(fields[1][0]);
- if(status!='L' && status!='E' && status!='C' && status!='S' && status!='F' && status!='I' && status!='T') {
- fprintf(stderr, "genprops: unrecognized status field in CaseFolding.txt at %s\n", fields[0][0]);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
-
- /* ignore all case folding mappings that are the same as the UnicodeData.txt lowercase mappings */
- if(status=='L') {
- return;
- }
-
- /* get the mapping */
- count=caseFoldings[caseFoldingCount].full[0]=
- (UChar)u_parseString(fields[2][0], caseFoldings[caseFoldingCount].full+1, 31, &caseFoldings[caseFoldingCount].simple, pErrorCode);
- if(U_FAILURE(*pErrorCode)) {
- fprintf(stderr, "genprops: error parsing CaseFolding.txt mapping at %s\n", fields[0][0]);
- exit(*pErrorCode);
- }
-
- /* there is a simple mapping only if there is exactly one code point (count is in UChars) */
- if(count==0 || count>2 || (count==2 && UTF_IS_SINGLE(caseFoldings[caseFoldingCount].full[1]))) {
- caseFoldings[caseFoldingCount].simple=0;
- }
-
- /* update the case-sensitive set */
- if(status!='T') {
- uset_add(caseSensitive, (UChar32)caseFoldings[caseFoldingCount].code);
- _set_addAll(caseSensitive, caseFoldings[caseFoldingCount].full+1, caseFoldings[caseFoldingCount].full[0]);
- }
-
- /* check the status */
- if(status=='S') {
- /* check if there was a full mapping for this code point before */
- if( caseFoldingCount>0 &&
- caseFoldings[caseFoldingCount-1].code==caseFoldings[caseFoldingCount].code &&
- caseFoldings[caseFoldingCount-1].status=='F'
- ) {
- /* merge the two entries */
- caseFoldings[caseFoldingCount-1].simple=caseFoldings[caseFoldingCount].simple;
- return;
- }
- } else if(status=='F') {
- /* check if there was a simple mapping for this code point before */
- if( caseFoldingCount>0 &&
- caseFoldings[caseFoldingCount-1].code==caseFoldings[caseFoldingCount].code &&
- caseFoldings[caseFoldingCount-1].status=='S'
- ) {
- /* merge the two entries */
- uprv_memcpy(caseFoldings[caseFoldingCount-1].full, caseFoldings[caseFoldingCount].full, 32*U_SIZEOF_UCHAR);
- return;
- }
- } else if(status=='I' || status=='T') {
- /* check if there was a default mapping for this code point before (remove it) */
- while(caseFoldingCount>0 &&
- caseFoldings[caseFoldingCount-1].code==caseFoldings[caseFoldingCount].code
- ) {
- prevCode=0;
- --caseFoldingCount;
- }
- /* store only a marker for special handling for cases like dotless i */
- caseFoldings[caseFoldingCount].simple=0;
- caseFoldings[caseFoldingCount].full[0]=0;
- }
-
- /* check that the code points (caseFoldings[caseFoldingCount].code) are in ascending order */
- if(caseFoldings[caseFoldingCount].code<=prevCode && caseFoldings[caseFoldingCount].code>0) {
- fprintf(stderr, "genprops: error - CaseFolding entries out of order, U+%04lx after U+%04lx\n",
- (unsigned long)caseFoldings[caseFoldingCount].code,
- (unsigned long)prevCode);
- *pErrorCode=U_PARSE_ERROR;
- exit(U_PARSE_ERROR);
- }
- prevCode=caseFoldings[caseFoldingCount].code;
-
- if(++caseFoldingCount==MAX_CASE_FOLDING_COUNT) {
- fprintf(stderr, "genprops: too many case folding mappings\n");
- *pErrorCode=U_INDEX_OUTOFBOUNDS_ERROR;
- exit(U_INDEX_OUTOFBOUNDS_ERROR);
- }
-}
-
-static void
-parseCaseFolding(const char *filename, UErrorCode *pErrorCode) {
- char *fields[3][2];
-
- if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
- return;
- }
-
- u_parseDelimitedFile(filename, ';', fields, 3, caseFoldingLineFn, NULL, pErrorCode);
-}
-