Get rid of code taken from bionic to avoid license issue.

Change-Id: If96f4247edbc7b1e9f7418d2ddef191618a54ae3
main
Ken Wakasa 2010-04-23 01:24:09 +09:00
parent 707505ec18
commit f1abb8ce3c
1 changed files with 13 additions and 20 deletions

View File

@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include <sys/types.h> #include <stdlib.h>
namespace latinime { namespace latinime {
@ -27,7 +27,7 @@ struct LatinCapitalSmallPair {
// //
// 1. Run the following code. Bascially taken from // 1. Run the following code. Bascially taken from
// Dictionary::toLowerCase(unsigned short c) in dictionary.cpp. // Dictionary::toLowerCase(unsigned short c) in dictionary.cpp.
// Then, get the list of chars where ccc != ccc2 above. // Then, get the list of chars where cc != ccc.
// //
// unsigned short c, cc, ccc, ccc2; // unsigned short c, cc, ccc, ccc2;
// for (c = 0; c < 0xFFFF ; c++) { // for (c = 0; c < 0xFFFF ; c++) {
@ -882,25 +882,18 @@ static const struct LatinCapitalSmallPair SORTED_CHAR_MAP[] = {
{ 0xFF3A, 0xFF5A } // FULLWIDTH LATIN CAPITAL LETTER Z { 0xFF3A, 0xFF5A } // FULLWIDTH LATIN CAPITAL LETTER Z
}; };
unsigned short latin_tolower(unsigned short c0) { static int compare_pair_capital(const void *a, const void *b) {
const struct LatinCapitalSmallPair *p; return (int)(*(unsigned short *)a)
const struct LatinCapitalSmallPair *base = SORTED_CHAR_MAP; - (int)((struct LatinCapitalSmallPair*)b)->capital;
int c = c0; }
int lim, cmp;
const size_t nmemb = sizeof(SORTED_CHAR_MAP) / sizeof(SORTED_CHAR_MAP[0]);
// Binary search: Taken from bionic unsigned short latin_tolower(unsigned short c) {
for (lim = nmemb; lim != 0; lim >>= 1) { struct LatinCapitalSmallPair *p =
p = base + (lim >> 1); (struct LatinCapitalSmallPair *)bsearch(&c, SORTED_CHAR_MAP,
cmp = c - (int)p->capital; sizeof(SORTED_CHAR_MAP) / sizeof(SORTED_CHAR_MAP[0]),
if (cmp == 0) sizeof(SORTED_CHAR_MAP[0]),
return p->small; compare_pair_capital);
if (cmp > 0) { /* key > p: move right */ return p ? p->small : c;
base = p + 1;
lim--;
} /* else move left */
}
return c0;
} }
} // namespace latinime } // namespace latinime