ITS#4724 revert prev commit, better fix.

This commit is contained in:
Howard Chu 2006-10-30 18:44:52 +00:00
parent 29fbd00272
commit 60a25c72ba
3 changed files with 27 additions and 23 deletions

View File

@ -313,6 +313,9 @@ ucisprop(ac_uint4 code, ac_uint4 mask1, ac_uint4 mask2)
#if !HARDCODE_DATA
/* These record the number of slots in the map.
* There are 3 words per slot.
*/
static ac_uint4 _uccase_size;
static ac_uint2 _uccase_len[2];
static ac_uint4 *_uccase_map;
@ -356,23 +359,23 @@ _uccase_load(char *paths, int reload)
* Set the node count and lengths of the upper and lower case mapping
* tables.
*/
_uccase_size = hdr.cnt * 3;
_uccase_len[0] = hdr.size.len[0] * 3;
_uccase_len[1] = hdr.size.len[1] * 3;
_uccase_size = hdr.cnt;
_uccase_len[0] = hdr.size.len[0];
_uccase_len[1] = hdr.size.len[1];
_uccase_map = (ac_uint4 *)
malloc(_uccase_size * sizeof(ac_uint4));
malloc(_uccase_size * 3 * sizeof(ac_uint4));
/*
* Load the case mapping table.
*/
fread((char *) _uccase_map, sizeof(ac_uint4), _uccase_size, in);
fread((char *) _uccase_map, sizeof(ac_uint4), _uccase_size * 3, in);
/*
* Do an endian swap if necessary.
*/
if (hdr.bom == 0xfffe) {
for (i = 0; i < _uccase_size; i++)
for (i = 0; i < _uccase_size * 3; i++)
_uccase_map[i] = endian_long(_uccase_map[i]);
}
fclose(in);
@ -394,6 +397,7 @@ static ac_uint4
_uccase_lookup(ac_uint4 code, long l, long r, int field)
{
long m;
ac_uint4 *tmp;
/*
* Do the binary search.
@ -404,13 +408,13 @@ _uccase_lookup(ac_uint4 code, long l, long r, int field)
* the beginning of a case mapping triple.
*/
m = (l + r) >> 1;
m -= (m % 3);
if (code > _uccase_map[m])
l = m + 3;
else if (code < _uccase_map[m])
r = m - 3;
else if (code == _uccase_map[m])
return _uccase_map[m + field];
tmp = &_uccase_map[m*3];
if (code > *tmp)
l = m + 1;
else if (code < *tmp)
r = m - 1;
else if (code == *tmp)
return tmp[field];
}
return code;
@ -431,14 +435,14 @@ uctoupper(ac_uint4 code)
*/
field = 2;
l = _uccase_len[0];
r = (l + _uccase_len[1]) - 3;
r = (l + _uccase_len[1]) - 1;
} else {
/*
* The character is title case.
*/
field = 1;
l = _uccase_len[0] + _uccase_len[1];
r = _uccase_size - 3;
r = _uccase_size - 1;
}
return _uccase_lookup(code, l, r, field);
}
@ -458,14 +462,14 @@ uctolower(ac_uint4 code)
*/
field = 1;
l = 0;
r = _uccase_len[0] - 3;
r = _uccase_len[0] - 1;
} else {
/*
* The character is title case.
*/
field = 2;
l = _uccase_len[0] + _uccase_len[1];
r = _uccase_size - 3;
r = _uccase_size - 1;
}
return _uccase_lookup(code, l, r, field);
}
@ -489,13 +493,13 @@ uctotitle(ac_uint4 code)
* The character is upper case.
*/
l = 0;
r = _uccase_len[0] - 3;
r = _uccase_len[0] - 1;
} else {
/*
* The character is lower case.
*/
l = _uccase_len[0];
r = (l + _uccase_len[1]) - 3;
r = (l + _uccase_len[1]) - 1;
}
return _uccase_lookup(code, l, r, field);
}

View File

@ -1409,10 +1409,10 @@ write_cdata(char *opath)
#if HARDCODE_DATA
fprintf(out, PREF "ac_uint4 _uccase_size = %ld;\n\n",
(long) (upper_used + lower_used + title_used)*3);
(long) (upper_used + lower_used + title_used));
fprintf(out, PREF "ac_uint2 _uccase_len[2] = {%ld, %ld};\n\n",
(long) upper_used*3, (long) lower_used*3);
(long) upper_used, (long) lower_used);
fprintf(out, PREF "ac_uint4 _uccase_map[] = {");
if (upper_used > 0)

View File

@ -1493,9 +1493,9 @@ static const ac_uint4 _ucprop_ranges[] = {
0x0000fe70, 0x0000fe74, 0x0000fe76, 0x0000fefc
};
static const ac_uint4 _uccase_size = 4512;
static const ac_uint4 _uccase_size = 1504;
static const ac_uint2 _uccase_len[2] = {2235, 2265};
static const ac_uint2 _uccase_len[2] = {745, 755};
static const ac_uint4 _uccase_map[] = {
0x00000041, 0x00000061, 0x00000041,