|
|
|
|
#include <wctype.h>
|
|
|
|
|
|
new wcwidth implementation (fast table-based)
i tried to go with improving the old binary-search-based algorithm,
but between growth in the number of ranges, bad performance, and lack
of confidence in the binary search code's stability under changes in
the table, i decided it was worth the extra 1.8k to have something
clean and maintainable.
also note that, like the alpha and punct tables, there's definitely
room to optimize the nonspacing/wide tables by overlapping subtables.
this is not a high priority, but i've begun looking into how to do it,
and i suspect the table sizes can be roughly halved. if that turns out
to be true, the new, fast, table-based implementation will be roughly
the same size as if i had just extended the old binary search one.
14 years ago
|
|
|
static unsigned char table[] = {
|
|
|
|
|
#include "nonspacing.h"
|
|
|
|
|
};
|
|
|
|
|
|
new wcwidth implementation (fast table-based)
i tried to go with improving the old binary-search-based algorithm,
but between growth in the number of ranges, bad performance, and lack
of confidence in the binary search code's stability under changes in
the table, i decided it was worth the extra 1.8k to have something
clean and maintainable.
also note that, like the alpha and punct tables, there's definitely
room to optimize the nonspacing/wide tables by overlapping subtables.
this is not a high priority, but i've begun looking into how to do it,
and i suspect the table sizes can be roughly halved. if that turns out
to be true, the new, fast, table-based implementation will be roughly
the same size as if i had just extended the old binary search one.
14 years ago
|
|
|
static unsigned char wtable[] = {
|
|
|
|
|
#include "wide.h"
|
|
|
|
|
};
|
|
|
|
|
|
new wcwidth implementation (fast table-based)
i tried to go with improving the old binary-search-based algorithm,
but between growth in the number of ranges, bad performance, and lack
of confidence in the binary search code's stability under changes in
the table, i decided it was worth the extra 1.8k to have something
clean and maintainable.
also note that, like the alpha and punct tables, there's definitely
room to optimize the nonspacing/wide tables by overlapping subtables.
this is not a high priority, but i've begun looking into how to do it,
and i suspect the table sizes can be roughly halved. if that turns out
to be true, the new, fast, table-based implementation will be roughly
the same size as if i had just extended the old binary search one.
14 years ago
|
|
|
int wcwidth(wint_t wc)
|
|
|
|
|
{
|
new wcwidth implementation (fast table-based)
i tried to go with improving the old binary-search-based algorithm,
but between growth in the number of ranges, bad performance, and lack
of confidence in the binary search code's stability under changes in
the table, i decided it was worth the extra 1.8k to have something
clean and maintainable.
also note that, like the alpha and punct tables, there's definitely
room to optimize the nonspacing/wide tables by overlapping subtables.
this is not a high priority, but i've begun looking into how to do it,
and i suspect the table sizes can be roughly halved. if that turns out
to be true, the new, fast, table-based implementation will be roughly
the same size as if i had just extended the old binary search one.
14 years ago
|
|
|
if (wc < 0xffU)
|
|
|
|
|
return (wc+1 & 0x7f) >= 0x21 ? 1 : wc ? -1 : 0;
|
|
|
|
|
if ((wc & 0xfffeffffU) < 0xfffe) {
|
|
|
|
|
if ((table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1)
|
|
|
|
|
return 0;
|
|
|
|
|
if ((wtable[wtable[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1)
|
|
|
|
|
return 2;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
if ((wc & 0xfffe) == 0xfffe)
|
|
|
|
|
return -1;
|
|
|
|
|
if (wc-0x20000U < 0x20000)
|
|
|
|
|
return 2;
|
|
|
|
|
if (wc == 0xe0001 || wc-0xe0020U < 0x5f || wc-0xe0100 < 0xef)
|
|
|
|
|
return 0;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|