Update of /cvsroot/mahogany/M/src/modules/viewflt
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9629/src/modules/viewflt
Modified Files:
QuoteURL.cpp
Log Message:
detect wrapped quoted lines
Index: QuoteURL.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/viewflt/QuoteURL.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -b -u -2 -r1.14 -r1.15
--- QuoteURL.cpp 26 Jul 2004 17:11:51 -0000 1.14
+++ QuoteURL.cpp 28 Jul 2004 22:19:49 -0000 1.15
@@ -73,7 +73,7 @@
// ----------------------------------------------------------------------------
-/** Count levels of quoting on the first line of passed string
- (i.e. before the first \n). It understands standard e-mail
- quoting methods such as ">" and "XY>"
+/** Count levels of quoting on the first line of passed string.
+
+ It understands standard e-mail quoting methods such as ">" and "XY>".
@param string the string to check
@@ -87,5 +87,6 @@
const char *prev,
int max_white,
- int max_alpha);
+ int max_alpha,
+ bool *nextWrapped);
/**
@@ -164,5 +165,7 @@
// get the quote level for the line (prev is for CountQuoteLevel() only)
- size_t GetQuotedLevel(const char *line, const char *prev) const;
+ size_t GetQuotedLevel(const char *line,
+ const char *prev,
+ bool *nextWrapped) const;
// get the colour for the given quote level
@@ -228,18 +231,15 @@
const char *prev,
int max_white,
- int max_alpha)
+ int max_alpha,
+ bool *nextWrapped)
{
+ *nextWrapped = false;
+
// find the beginning of the and next line
- const char *next = strchr(string, '\n');
- if ( !next )
- {
+ const char *nextStart = strchr(string, '\n');
+
// it's simpler to pretend that the next line is the same as this one
// instead of checking for it all the time below
- next = string;
- }
- else // skip '\n'
- {
- next++;
- }
+ const char *next = nextStart ? nextStart + 1 /* skip '\n' */ : string;
if ( !prev )
@@ -302,13 +302,38 @@
{
// but then it diverges, so this is unlikely to be a quote marker
- break;
+ sameAsNext = Line_Different;
}
}
- else // not the same one, but maybe the next line is blank?
+ else // not the same one
{
- if ( !IsBlankLine(next + 1) )
+ // if the next line is blank, this one is considered to be quoted
+ // (otherwise the last line of a quoted paragraph would never be
+ // recognized as quoted)
+ sameAsNext = IsBlankLine(next + 1) ? Line_Blank : Line_Different;
+ }
+
+ // last chance: it is possible that the next line is a wrapped part of
+ // this one, so check the line after it too
+ //
+ // as this has a lot of potential for false positives, only do it for the
+ // most common quoting character
+ if ( sameAsNext == Line_Different && nextStart && *c == '>' )
+ {
+ const char *nextnext = strchr(nextStart + 1 /* skip '\n' */, '\n');
+ if ( !nextnext ||
+ (!IsBlankLine(nextnext + 1) &&
+ strncmp(string, nextnext + 1, next - nextStart + 1) != 0) )
+ {
+ // the line after next doesn't start with the same prefix as
+ // this one so it's improbable that the next line was garbled
+ // because of quoting -- chances are this line is simply not
+ // quoted at all
break;
}
+ // it does look like the next line is wrapped tail of this one
+ *nextWrapped = true;
+ }
+
// finally check the previous line
if ( sameAsPrev == Line_Same && *prev != *c )
@@ -387,5 +412,7 @@
size_t
-QuoteURLFilter::GetQuotedLevel(const char *line, const char *prev) const
+QuoteURLFilter::GetQuotedLevel(const char *line,
+ const char *prev,
+ bool *nextWrapped) const
{
size_t qlevel = CountQuoteLevel
@@ -394,5 +421,6 @@
prev,
m_options.quotedMaxWhitespace,
- m_options.quotedMaxAlpha
+ m_options.quotedMaxAlpha,
+ nextWrapped
);
@@ -440,5 +468,8 @@
before;
- size_t levelBeforeURL = LEVEL_INVALID;
+ size_t level = LEVEL_INVALID,
+ levelBeforeURL = LEVEL_INVALID;
+
+ bool nextWrapped = false;
do
@@ -460,6 +491,4 @@
if ( m_options.quotedColourize )
{
- size_t level;
-
// if we have just inserted an URL, restore the same level we were
// using before as otherwise foo in a line like "> URL foo" wouldn't
@@ -472,5 +501,8 @@
else // no preceding URL, we're really at the start of line
{
- level = GetQuotedLevel(before, NULL);
+ if ( nextWrapped )
+ nextWrapped = false;
+ else
+ level = GetQuotedLevel(before, NULL, &nextWrapped);
}
@@ -486,5 +518,12 @@
// calculate the quoting level for this line
- size_t levelNew = GetQuotedLevel(lineNext, lineCur);
+ if ( nextWrapped )
+ {
+ // quoting level doesn't change anyhow
+ nextWrapped = false;
+ }
+ else
+ {
+ size_t levelNew = GetQuotedLevel(lineNext, lineCur, &nextWrapped);
if ( levelNew != level )
{
@@ -498,4 +537,5 @@
}
//else: same level as the previous line, just continue
+ }
if ( !*lineNext )
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates