|
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.20 2007-01-19 15:22:50 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: plaintorich.cpp,v 1.21 2007-05-23 09:19:48 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
|
|
... |
|
... |
299 |
// will be handled during output.
|
299 |
// will be handled during output.
|
300 |
std::sort(tboffs.begin(), tboffs.end(), PairIntCmpFirst());
|
300 |
std::sort(tboffs.begin(), tboffs.end(), PairIntCmpFirst());
|
301 |
return true;
|
301 |
return true;
|
302 |
}
|
302 |
}
|
303 |
|
303 |
|
|
|
304 |
// Setting searchable beacons in the text to walk the term list.
|
304 |
const char *firstTermAnchorName = "FIRSTTERM";
|
305 |
static const char *termAnchorNameBase = "FIRSTTERM";
|
|
|
306 |
string termAnchorName(int i)
|
|
|
307 |
{
|
|
|
308 |
char acname[sizeof(termAnchorNameBase) + 20];
|
|
|
309 |
sprintf(acname, "%s%d", termAnchorNameBase, i);
|
|
|
310 |
return string(acname);
|
|
|
311 |
}
|
305 |
|
312 |
|
306 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
313 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
307 |
const char *firstTermBeacon = "\xe2\xa0\x91\xe2\x96\x9f\x20\x01\x9a";
|
314 |
// 0xcd8f is utf8 for unicode 034F COMBINING GRAPHEME JOINER
|
|
|
315 |
// Qt doesn't display it, but accepts to search for it.
|
|
|
316 |
const char *firstTermBeacon = "\xcd\x8f\xcd\x8f\xcd\x8f\xcd\x8f";
|
308 |
#endif
|
317 |
#endif
|
|
|
318 |
|
|
|
319 |
static string termBeacon(int i)
|
|
|
320 |
{
|
|
|
321 |
return string("<a name=\"") + termAnchorName(i) + "\">"
|
|
|
322 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
|
323 |
+ "<font color=\"white\">" + firstTermBeacon + "</font>"
|
|
|
324 |
#endif
|
|
|
325 |
+ "</a>";
|
|
|
326 |
|
|
|
327 |
}
|
|
|
328 |
|
309 |
|
329 |
|
310 |
// Fix result text for display inside the gui text window.
|
330 |
// Fix result text for display inside the gui text window.
|
311 |
//
|
331 |
//
|
312 |
// To compute the term character positions in the output text, we used
|
332 |
// To compute the term character positions in the output text, we used
|
313 |
// to emulate how qt's textedit counts chars (ignoring tags and
|
333 |
// to emulate how qt's textedit counts chars (ignoring tags and
|
|
... |
|
... |
316 |
// don't know the term par/car positions in the editor text. Instead,
|
336 |
// don't know the term par/car positions in the editor text. Instead,
|
317 |
// we return the first term encountered, and the caller will use the
|
337 |
// we return the first term encountered, and the caller will use the
|
318 |
// editor's find() function to position on it
|
338 |
// editor's find() function to position on it
|
319 |
bool plaintorich(const string& in, string& out,
|
339 |
bool plaintorich(const string& in, string& out,
|
320 |
const HiliteData& hdata,
|
340 |
const HiliteData& hdata,
|
321 |
bool noHeader, bool fft)
|
341 |
bool noHeader, bool)
|
322 |
{
|
342 |
{
|
323 |
Chrono chron;
|
343 |
Chrono chron;
|
324 |
out.erase();
|
344 |
out.erase();
|
325 |
const vector<string>& terms(hdata.terms);
|
345 |
const vector<string>& terms(hdata.terms);
|
326 |
const vector<vector<string> >& groups(hdata.groups);
|
346 |
const vector<vector<string> >& groups(hdata.groups);
|
|
... |
|
... |
373 |
|
393 |
|
374 |
// Input character iterator
|
394 |
// Input character iterator
|
375 |
Utf8Iter chariter(in);
|
395 |
Utf8Iter chariter(in);
|
376 |
// State variable used to limitate the number of consecutive empty lines
|
396 |
// State variable used to limitate the number of consecutive empty lines
|
377 |
int ateol = 0;
|
397 |
int ateol = 0;
|
378 |
// State variable to update the char pos only for the first of
|
398 |
|
379 |
// consecutive blank chars
|
399 |
// Stuff for numbered anchors at each term match
|
380 |
int atblank = 0;
|
400 |
int anchoridx = 1;
|
|
|
401 |
|
381 |
for (string::size_type pos = 0; pos != string::npos; pos = chariter++) {
|
402 |
for (string::size_type pos = 0; pos != string::npos; pos = chariter++) {
|
382 |
if ((pos & 0xfff) == 0) {
|
403 |
if ((pos & 0xfff) == 0) {
|
383 |
CancelCheck::instance().checkCancel();
|
404 |
CancelCheck::instance().checkCancel();
|
384 |
}
|
405 |
}
|
|
|
406 |
|
385 |
// If we still have terms positions, check (byte) position
|
407 |
// If we still have terms positions, check (byte) position. If
|
|
|
408 |
// we are at or after a term match, mark.
|
386 |
if (tPosIt != tboffsend) {
|
409 |
if (tPosIt != tboffsend) {
|
387 |
int ibyteidx = chariter.getBpos();
|
410 |
int ibyteidx = chariter.getBpos();
|
388 |
|
|
|
389 |
if (fft && ibyteidx == cb.m_firstTermBPos) {
|
|
|
390 |
out += string("<a name=\"") + firstTermAnchorName + "\"> "
|
|
|
391 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
|
392 |
+ "<font color=\"white\"> " + firstTermBeacon + " </font> "
|
|
|
393 |
#endif
|
|
|
394 |
+ "</a>";
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
if (ibyteidx == tPosIt->first) {
|
411 |
if (ibyteidx == tPosIt->first) {
|
|
|
412 |
out += termBeacon(anchoridx++);
|
398 |
out += "<termtag>";
|
413 |
out += "<termtag>";
|
399 |
} else if (ibyteidx == tPosIt->second) {
|
414 |
} else if (ibyteidx == tPosIt->second) {
|
400 |
// Output end tag, then skip all highlight areas that
|
415 |
// Output end tag, then skip all highlight areas that
|
401 |
// would overlap this one
|
416 |
// would overlap this one
|
402 |
out += "</termtag>";
|
417 |
out += "</termtag>";
|
403 |
int crend = tPosIt->second;
|
418 |
int crend = tPosIt->second;
|
404 |
while (tPosIt != cb.tboffs.end() && tPosIt->first < crend)
|
419 |
while (tPosIt != cb.tboffs.end() && tPosIt->first < crend)
|
405 |
tPosIt++;
|
420 |
tPosIt++;
|
406 |
}
|
421 |
}
|
407 |
}
|
422 |
}
|
|
|
423 |
|
408 |
switch(*chariter) {
|
424 |
switch(*chariter) {
|
409 |
case '\n':
|
425 |
case '\n':
|
410 |
if (ateol < 2) {
|
426 |
if (ateol < 2) {
|
411 |
out += "<br>\n";
|
427 |
out += "<br>\n";
|
412 |
ateol++;
|
428 |
ateol++;
|
|
... |
|
... |
422 |
ateol = 0;
|
438 |
ateol = 0;
|
423 |
out += "&";
|
439 |
out += "&";
|
424 |
break;
|
440 |
break;
|
425 |
default:
|
441 |
default:
|
426 |
// We don't change the eol status for whitespace, want a real line
|
442 |
// We don't change the eol status for whitespace, want a real line
|
427 |
if (*chariter == ' ' || *chariter == '\t') {
|
443 |
if (!(*chariter == ' ' || *chariter == '\t')) {
|
428 |
atblank = 1;
|
|
|
429 |
} else {
|
|
|
430 |
ateol = 0;
|
444 |
ateol = 0;
|
431 |
atblank = 0;
|
|
|
432 |
}
|
445 |
}
|
433 |
chariter.appendchartostring(out);
|
446 |
chariter.appendchartostring(out);
|
434 |
}
|
447 |
}
|
435 |
}
|
448 |
}
|
436 |
#if 0
|
449 |
#if 0
|