#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;
* 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);
_uccase_lookup(ac_uint4 code, long l, long r, int field)
{
long m;
+ ac_uint4 *tmp;
/*
* Do the binary search.
* 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;
*/
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);
}
*/
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);
}
* 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);
}
#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)