|
a/src/qtgui/plaintorich.cpp |
|
b/src/qtgui/plaintorich.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.29 2007-10-18 10:39:41 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.30 2007-11-15 18:05:32 dockes Exp $ (C) 2005 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
307 |
char acname[sizeof(termAnchorNameBase) + 20];
|
307 |
char acname[sizeof(termAnchorNameBase) + 20];
|
308 |
sprintf(acname, "%s%d", termAnchorNameBase, i);
|
308 |
sprintf(acname, "%s%d", termAnchorNameBase, i);
|
309 |
return string(acname);
|
309 |
return string(acname);
|
310 |
}
|
310 |
}
|
311 |
|
311 |
|
312 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
|
313 |
// qtextedit scrolltoanchor(), which we would like to use to walk the
|
|
|
314 |
// search hit positions does not work well. So we mark the positions with
|
|
|
315 |
// a special string which we then use with the find() function for positionning
|
|
|
316 |
// We used to use some weird utf8 char for this, but this was displayed
|
|
|
317 |
// inconsistently depending of system, font, etc. We now use a good ole ctl
|
|
|
318 |
// char which doesnt' seem to cause any trouble. Wanted to use ^L, but can't
|
|
|
319 |
// be searched, so ^G
|
|
|
320 |
const char *firstTermBeacon = "\007";
|
|
|
321 |
#endif
|
|
|
322 |
|
|
|
323 |
static string termBeacon(int i)
|
312 |
static string termBeacon(int i)
|
324 |
{
|
313 |
{
|
325 |
return string("<a name=\"") + termAnchorName(i) + "\">"
|
314 |
return string("<a name=\"") + termAnchorName(i) + "\">";
|
326 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
|
327 |
+ firstTermBeacon
|
|
|
328 |
#endif
|
|
|
329 |
+ "</a>";
|
|
|
330 |
}
|
315 |
}
|
331 |
|
316 |
|
332 |
|
317 |
|
333 |
// Fix result text for display inside the gui text window.
|
318 |
// Fix result text for display inside the gui text window.
|
334 |
//
|
319 |
//
|
|
... |
|
... |
340 |
// Instead, we mark the search term positions either with html anchor
|
325 |
// Instead, we mark the search term positions either with html anchor
|
341 |
// (qt currently has problems with them), or a special string, and the
|
326 |
// (qt currently has problems with them), or a special string, and the
|
342 |
// caller will use the editor's find() function to position on it
|
327 |
// caller will use the editor's find() function to position on it
|
343 |
bool plaintorich(const string& in, list<string>& out,
|
328 |
bool plaintorich(const string& in, list<string>& out,
|
344 |
const HiliteData& hdata,
|
329 |
const HiliteData& hdata,
|
345 |
bool noHeader, bool needBeacons, int chunksize)
|
330 |
bool noHeader, int *lastAnchor, int chunksize)
|
346 |
{
|
331 |
{
|
347 |
Chrono chron;
|
332 |
Chrono chron;
|
348 |
const vector<string>& terms(hdata.terms);
|
333 |
const vector<string>& terms(hdata.terms);
|
349 |
const vector<vector<string> >& groups(hdata.groups);
|
334 |
const vector<vector<string> >& groups(hdata.groups);
|
350 |
const vector<int>& slacks(hdata.gslks);
|
335 |
const vector<int>& slacks(hdata.gslks);
|
|
... |
|
... |
414 |
// If we still have terms positions, check (byte) position. If
|
399 |
// If we still have terms positions, check (byte) position. If
|
415 |
// we are at or after a term match, mark.
|
400 |
// we are at or after a term match, mark.
|
416 |
if (tPosIt != tboffsend) {
|
401 |
if (tPosIt != tboffsend) {
|
417 |
int ibyteidx = chariter.getBpos();
|
402 |
int ibyteidx = chariter.getBpos();
|
418 |
if (ibyteidx == tPosIt->first) {
|
403 |
if (ibyteidx == tPosIt->first) {
|
419 |
if (needBeacons)
|
404 |
if (lastAnchor)
|
420 |
*sit += termBeacon(anchoridx++);
|
405 |
*sit += termBeacon(anchoridx++);
|
421 |
*sit += "<termtag>";
|
406 |
*sit += "<termtag>";
|
422 |
} else if (ibyteidx == tPosIt->second) {
|
407 |
} else if (ibyteidx == tPosIt->second) {
|
423 |
// Output end tag, then skip all highlight areas that
|
408 |
// Output end tag, then skip all highlight areas that
|
424 |
// would overlap this one
|
409 |
// would overlap this one
|
|
... |
|
... |
459 |
ateol = 0;
|
444 |
ateol = 0;
|
460 |
}
|
445 |
}
|
461 |
chariter.appendchartostring(*sit);
|
446 |
chariter.appendchartostring(*sit);
|
462 |
}
|
447 |
}
|
463 |
}
|
448 |
}
|
|
|
449 |
if (lastAnchor)
|
|
|
450 |
*lastAnchor = anchoridx - 1;
|
464 |
#if 0
|
451 |
#if 0
|
465 |
{
|
452 |
{
|
466 |
FILE *fp = fopen("/tmp/debugplaintorich", "a");
|
453 |
FILE *fp = fopen("/tmp/debugplaintorich", "a");
|
467 |
fprintf(fp, "BEGINOFPLAINTORICHOUTPUT\n");
|
454 |
fprintf(fp, "BEGINOFPLAINTORICHOUTPUT\n");
|
468 |
for (list<string>::iterator it = out.begin();
|
455 |
for (list<string>::iterator it = out.begin();
|