1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 03:32:24 +00:00

dtinfo: fix a highlighting issue.

This commit is contained in:
Liang Chang 2022-01-29 21:21:01 +08:00
parent ec433c3eaa
commit ec2fa5bb78
3 changed files with 104 additions and 59 deletions

View file

@ -256,31 +256,40 @@ DtCvStrVccToIndex(_DtCvSegment* seg, unsigned int vcc)
if (seg->type & _DtCvWIDE_CHAR) { if (seg->type & _DtCvWIDE_CHAR) {
wchar_t* seg_str = (wchar_t*)seg->handle.string.string; wchar_t* seg_str = (wchar_t*)seg->handle.string.string;
for (; *seg_str && rel_vcc > 0; seg_str++, index++) { for (; *seg_str && rel_vcc > 0; seg_str++, index++) {
if (*seg_str != ' ' && *seg_str != '\t' && *seg_str != '\n') if (!isspace(*seg_str))
rel_vcc--; rel_vcc--;
} }
if (*seg_str == 0 && rel_vcc > 0) if (*seg_str == 0 && rel_vcc > 0)
index = (unsigned int)-1; index = (unsigned int)-1;
else { else {
for (; *seg_str; seg_str++, index++) { for (; *seg_str; seg_str++, index++) {
if (*seg_str != ' ' && *seg_str != '\t' && *seg_str != '\n') if (!isspace(*seg_str))
break; break;
} }
} }
} }
else { else {
unsigned char* seg_str = (unsigned char*)seg->handle.string.string; unsigned char* seg_str = (unsigned char*)seg->handle.string.string;
for (; *seg_str && rel_vcc > 0; seg_str++, index++) { while (*seg_str && rel_vcc > 0) {
if (*seg_str != ' ' && *seg_str != '\t' && if (!isspace(*seg_str))
*seg_str != '\n' && *seg_str != 0xA0)
rel_vcc--; rel_vcc--;
int mbl = mblen((char *) seg_str, MB_CUR_MAX);
if (mbl < 0) {
++seg_str;
++index;
}
else {
seg_str += mbl;
index += mbl;
}
} }
if (*seg_str == 0 && rel_vcc > 0) if (*seg_str == 0 && rel_vcc > 0)
index = (unsigned int)-1; index = (unsigned int)-1;
else { else {
for (; *seg_str; seg_str++, index++) { for (; *seg_str; seg_str++, index++) {
if (*seg_str != ' ' && *seg_str != '\t' && if (!isspace(*seg_str))
*seg_str != '\n' && *seg_str != 0xA0)
break; break;
} }
} }
@ -301,16 +310,20 @@ DtCvStrVcLenSync(_DtCvSegment* seg)
if (seg->type & _DtCvWIDE_CHAR) { if (seg->type & _DtCvWIDE_CHAR) {
wchar_t* seg_str = (wchar_t*)seg->handle.string.string; wchar_t* seg_str = (wchar_t*)seg->handle.string.string;
for (; *seg_str; seg_str++) { for (; *seg_str; seg_str++) {
if (*seg_str != ' ' && *seg_str != '\t' && *seg_str != '\n') if (!isspace(*seg_str))
vclen++; vclen++;
} }
} }
else { else {
unsigned char* seg_str = (unsigned char*)seg->handle.string.string; unsigned char* seg_str = (unsigned char*)seg->handle.string.string;
for (; *seg_str; seg_str++) { while (*seg_str) {
if (*seg_str != ' ' && *seg_str != '\t' && if (!isspace(*seg_str))
*seg_str != '\n' && *seg_str != 0xA0)
vclen++; vclen++;
int mbl = mblen((char *) seg_str, MB_CUR_MAX);
if (mbl < 0) ++seg_str;
else seg_str += mbl;
} }
} }
@ -459,15 +472,16 @@ chop_segment(_DtCvSegment* seg, unsigned int nc)
// the segment to be highlighted // the segment to be highlighted
_DtCvSegment* _DtCvSegment*
highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len) highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int vlen)
{ {
if (seg == NULL || (seg->type & _DtCvPRIMARY_MASK) != _DtCvSTRING) if (seg == NULL || (seg->type & _DtCvPRIMARY_MASK) != _DtCvSTRING)
return NULL; return NULL;
if (len <= 0) if (vlen <= 0)
return NULL; return NULL;
unsigned int seg_vcc = DtCvStrVcc(seg); unsigned int seg_vcc = DtCvStrVcc(seg);
unsigned int seg_vc_len = DtCvStrVcLen(seg);
unsigned int seg_nc = DtCvStrLen(seg); unsigned int seg_nc = DtCvStrLen(seg);
if (vcc < seg_vcc) // vcc falls short if (vcc < seg_vcc) // vcc falls short
@ -480,17 +494,22 @@ highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len)
if (nseg_nc == (unsigned int)-1) // vcc is beyond segment if (nseg_nc == (unsigned int)-1) // vcc is beyond segment
return NULL; return NULL;
unsigned int rel_vcc = vcc - ((SegClientData*)seg->client_use)->vcc();
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "(DEBUG) vcc=%d, index=%d, clen=%d\n", vcc, nseg_nc, len); fprintf(stderr, "(DEBUG) vcc=%d, index=%d, vlen=%d\n", vcc, nseg_nc, vlen);
#endif #endif
if (len == 0) if (vlen == 0)
return NULL; return NULL;
else if (seg_vcc == vcc && seg_nc == len) else if (seg_vcc == vcc && seg_vc_len == vlen)
return seg; return seg;
if (len > seg_nc - nseg_nc) { // len goes beyond this segment unsigned int len = 0;
if (vlen > seg_vc_len - rel_vcc) { // vlen goes beyond this segment
if (seg->next_seg == NULL) { if (seg->next_seg == NULL) {
vlen = seg_vc_len - rel_vcc;
len = seg_nc - nseg_nc; len = seg_nc - nseg_nc;
} }
else { else {
@ -499,6 +518,7 @@ highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len)
if (type != _DtCvSTRING || sibling->client_use == NULL || if (type != _DtCvSTRING || sibling->client_use == NULL ||
DtCvStrVcc(sibling) == (unsigned int)-1 || DtCvStrVcc(sibling) == (unsigned int)-1 ||
(seg->type & _DtCvWIDE_CHAR) != (sibling->type & _DtCvWIDE_CHAR)) { (seg->type & _DtCvWIDE_CHAR) != (sibling->type & _DtCvWIDE_CHAR)) {
vlen = seg_vc_len - rel_vcc;
len = seg_nc - nseg_nc; len = seg_nc - nseg_nc;
} }
else { // let's merge segments else { // let's merge segments
@ -510,23 +530,23 @@ highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len)
if (widec) { if (widec) {
wchar_t* src = (wchar_t*)sibling->handle.string.string; wchar_t* src = (wchar_t*)sibling->handle.string.string;
wchar_t* dst = (wchar_t*)seg->handle.string.string; wchar_t* dst = (wchar_t*)seg->handle.string.string;
int slen = wcslen(dst); int dlen = wcslen(dst);
int len = wcslen(src); int slen = wcslen(src);
seg->handle.string.string = (void*) seg->handle.string.string = (void*)
realloc(seg->handle.string.string, realloc(seg->handle.string.string,
sizeof(wchar_t) * (slen + len + 1)); sizeof(wchar_t) * (dlen + slen + 1));
dst = (wchar_t*)seg->handle.string.string; dst = (wchar_t*)seg->handle.string.string;
*((char *) memcpy(dst + slen, src, len) + len) = '\0'; *((char *) memcpy(dst + dlen, src, slen) + slen) = '\0';
} }
else { else {
char* src = (char*)sibling->handle.string.string; char* src = (char*)sibling->handle.string.string;
char* dst = (char*)seg->handle.string.string; char* dst = (char*)seg->handle.string.string;
int slen = strlen(dst); int dlen = strlen(dst);
int len = strlen(src); int slen = strlen(src);
seg->handle.string.string = (void*) seg->handle.string.string = (void*)
realloc(seg->handle.string.string, slen + len + 1); realloc(seg->handle.string.string, dlen + slen + 1);
dst = (char*)seg->handle.string.string; dst = (char*)seg->handle.string.string;
*((char *) memcpy(dst + slen, src, len) + len) = '\0'; *((char *) memcpy(dst + dlen, src, slen) + slen) = '\0';
} }
DtCvStrVcLenSync(seg); DtCvStrVcLenSync(seg);
@ -539,7 +559,44 @@ highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len)
// NOTE: sibling is kept (i.e. not deleted) // NOTE: sibling is kept (i.e. not deleted)
// this fact may cause problems in next highlight_search_hit // this fact may cause problems in next highlight_search_hit
return highlight_search_hit(seg, vcc, len); return highlight_search_hit(seg, vcc, vlen);
}
}
}
else if (vlen < seg_vc_len - rel_vcc) {
if (widec) len = vlen;
else {
unsigned char *seg_str = (unsigned char*)seg->handle.string.string;
for (int i = 0; i < rel_vcc; ++i) {
if (isspace(*seg_str)) {
++seg_str;
continue;
}
int mbl = mblen((char *) seg_str, MB_CUR_MAX);
if (mbl < 0) ++seg_str;
else seg_str += mbl;
}
for (int i = 0; i < vlen; ++i) {
if (isspace(*seg_str)) {
++seg_str;
++len;
continue;
}
int mbl = mblen((char *) seg_str, MB_CUR_MAX);
if (mbl < 0) {
++seg_str;
++len;
}
else {
seg_str += mbl;
len += mbl;
}
} }
} }
} }
@ -563,7 +620,7 @@ highlight_search_hit(_DtCvSegment* seg, unsigned int vcc, unsigned int len)
return NULL; return NULL;
} }
if (len != seg_nc - nseg_nc) if (vlen != seg_vc_len - rel_vcc)
chop_segment(seg, len); chop_segment(seg, len);
return seg; return seg;

View file

@ -1282,10 +1282,7 @@ CanvasRenderer::handle_olias_attributes(ElementFeatures &features,
assert( mb_len > 0 ); assert( mb_len > 0 );
if (mb_len == 1) { if (mb_len == 1) {
const unsigned char ch = (unsigned char)*p++; const unsigned char ch = (unsigned char)*p++;
if (ch == ' ' || // space if (isspace(ch))
ch == '\t' || // tab
ch == '\n' || // newline
ch == 0xA0) // nbsp
continue; continue;
} }
else else
@ -1296,10 +1293,7 @@ CanvasRenderer::handle_olias_attributes(ElementFeatures &features,
#else #else
while (*p) while (*p)
{ {
if (!((*p == ' ') || // space if (!isspace(*p))
(*p == ' ') || // tab
(*p == '\n') || // newline
(*p == (char)0xA0))) // nbsp
{ {
vcc++ ; vcc++ ;
} }
@ -1679,15 +1673,21 @@ CanvasRenderer::really_insert_string (_DtCvSegment *container,
if (strseg->type & _DtCvWIDE_CHAR) { if (strseg->type & _DtCvWIDE_CHAR) {
wchar_t *p; wchar_t *p;
for (p = (wchar_t*)string; *p; p++) { for (p = (wchar_t*)string; *p; p++) {
if (*p != ' ' && *p != '\t' && *p != '\n') if (!isspace(*p))
scd.vclen()++; scd.vclen()++;
} }
} }
else { // also need to exclude nbsp else {
unsigned char* p; unsigned char* p = (unsigned char *) string;
for (p = (unsigned char*)string; *p; p++) {
if (*p != ' ' && *p != '\t' && *p != '\n' && *p != 0xA0) while (*p) {
int mbl = mblen((char *) p, MB_CUR_MAX);
if (!isspace(*p))
scd.vclen()++; scd.vclen()++;
if (mbl < 0) ++p;
else p += mbl;
} }
} }

View file

@ -395,8 +395,7 @@ DtSR_SearchResultsEntry::create_matches()
while (off > 0) { while (off > 0) {
int scanned = 0; int scanned = 0;
if (*cursor == '\n' || *cursor == '\t' || *cursor == ' ' || if (isspace(*cursor)) {
*cursor == 0x0D) {
scanned++; scanned++;
} }
else if (*cursor == ShiftIn || *cursor == ShiftOut) { else if (*cursor == ShiftIn || *cursor == ShiftOut) {
@ -407,20 +406,11 @@ DtSR_SearchResultsEntry::create_matches()
scanned++; scanned++;
} }
else { else {
int mbl = mblen(cursor, MB_CUR_MAX); scanned = mblen(cursor, MB_CUR_MAX);
vcc++;
if ((mbl == 1 && (unsigned char) cursor[0] == 0xA0) || /* skip one byte in case of failure */
(mbl == 2 && (unsigned char) cursor[0] == 0xC2 && if (scanned < 0) scanned = 1;
(unsigned char) cursor[1] == 0xA0)) {
scanned++;
}
else {
scanned = mbl;
vcc++;
/* skip one byte in case of failure */
if (scanned < 0) scanned = 1;
}
} }
off -= scanned; off -= scanned;
@ -434,13 +424,11 @@ DtSR_SearchResultsEntry::create_matches()
int len = atoi(len_str); int len = atoi(len_str);
// remove leading white-spaces // remove leading white-spaces
for (; len && (*cursor == ' ' || *cursor == '\t' || for (; len && isspace(*cursor); cursor++, len--);
*cursor == '\n'|| *cursor == 0x0D); cursor++, len--);
// remove trailing white-spaces // remove trailing white-spaces
if (len > 0) { if (len > 0) {
for (const char* p = cursor + len - 1; for (const char *p = cursor + len - 1; isspace(*p); p--, len--);
*p==' ' || *p=='\t' || *p=='\n' || *p==0x0D; p--, len--);
} }
if (len == 0) if (len == 0)