mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
The end condition in the binary search loop in the new getType() was
incorrect. I must have written that binary search idiom a hundred times, so it's rather embarrassing that I can't _automatically_ get it right! This was causing all kinds of characters to be classified as ON when they should have been various other classes. Also while I'm here, I've added another test case to utf8.txt (a small piece of Arabic within a predominantly L->R line), and also supplied a means to compile minibidi.c with -DTEST_GETTYPE to produce a command-line character class lookup tool. (Not sure what use that'll be _other_ than debugging this precise problem, but I don't like to throw it away now I've written it :-) [originally from svn r5016]
This commit is contained in:
parent
4cae179ff8
commit
e202f0f228
54
minibidi.c
54
minibidi.c
@ -38,6 +38,14 @@
|
||||
#define OISL 0x80 /* Override is L */
|
||||
#define OISR 0x40 /* Override is R */
|
||||
|
||||
/* For standalone compilation in a testing mode.
|
||||
* Still depends on the PuTTY headers for snewn and sfree, but can avoid
|
||||
* _linking_ with any other PuTTY code. */
|
||||
#ifdef TEST_GETTYPE
|
||||
#define safemalloc malloc
|
||||
#define safefree free
|
||||
#endif
|
||||
|
||||
/* Shaping Helpers */
|
||||
#define STYPE(xh) ((((xh) >= SHAPE_FIRST) && ((xh) <= SHAPE_LAST)) ? \
|
||||
shapetypes[(xh)-SHAPE_FIRST].type : SU) /*))*/
|
||||
@ -848,7 +856,7 @@ unsigned char getType(int ch)
|
||||
i = -1;
|
||||
j = lenof(lookup);
|
||||
|
||||
while (j - i > 2) {
|
||||
while (j - i > 1) {
|
||||
k = (i + j) / 2;
|
||||
if (ch < lookup[k].first)
|
||||
j = k;
|
||||
@ -1810,3 +1818,47 @@ void doMirror(wchar_t* ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TEST_GETTYPE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
static const struct { int type; char *name; } typetoname[] = {
|
||||
#define TYPETONAME(X) { X , #X }
|
||||
TYPETONAME(L),
|
||||
TYPETONAME(LRE),
|
||||
TYPETONAME(LRO),
|
||||
TYPETONAME(R),
|
||||
TYPETONAME(AL),
|
||||
TYPETONAME(RLE),
|
||||
TYPETONAME(RLO),
|
||||
TYPETONAME(PDF),
|
||||
TYPETONAME(EN),
|
||||
TYPETONAME(ES),
|
||||
TYPETONAME(ET),
|
||||
TYPETONAME(AN),
|
||||
TYPETONAME(CS),
|
||||
TYPETONAME(NSM),
|
||||
TYPETONAME(BN),
|
||||
TYPETONAME(B),
|
||||
TYPETONAME(S),
|
||||
TYPETONAME(WS),
|
||||
TYPETONAME(ON),
|
||||
#undef TYPETONAME
|
||||
};
|
||||
int i;
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
unsigned long chr = strtoul(argv[i], NULL, 0);
|
||||
int type = getType(chr);
|
||||
assert(typetoname[type].type == type);
|
||||
printf("U+%04x: %s\n", chr, typetoname[type].name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
1
testdata/utf8.txt
vendored
1
testdata/utf8.txt
vendored
@ -18,3 +18,4 @@ Arabic and bidirectional text:
|
||||
(من مجمع الزوائد ومنبع الفوائد للهيثمي ، ج 1 ، ص 74-84)
|
||||
عن [44mجرير[m [41mرضي[m الله عنه قال قال رسول الله صلى الله عليه
|
||||
وسلم: بني الاسلام على خمس شهادة ان لا اله الا الله واقام
|
||||
Mixed LTR and RTL text: [44mجرير[m [41mرضي[m back to LTR.
|
||||
|
Loading…
Reference in New Issue
Block a user