Update of /cvsroot/mahogany/M/src/modules/viewflt
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17582/src/modules/viewflt

Modified Files:
        QuoteURL.cpp 
Log Message:
corrected quoting level detection for the cases when the next/prev lines are empty

Index: QuoteURL.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/viewflt/QuoteURL.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -b -u -2 -r1.13 -r1.14
--- QuoteURL.cpp        26 Jul 2004 12:25:03 -0000      1.13
+++ QuoteURL.cpp        26 Jul 2004 17:11:51 -0000      1.14
@@ -197,4 +197,31 @@
 }
 
+enum LineResult
+{
+   Line_Blank = -2,
+   Line_Unknown = -1,
+   Line_Different,
+   Line_Same
+};
+
+// advance the *pp pointer if it points to the same thing as c
+static void
+UpdateLineStatus(const char *c, const char **pp, LineResult *pSameAs)
+{
+   if ( *pSameAs == Line_Unknown || *pSameAs == Line_Same )
+   {
+      if ( **pp != *c )
+      {
+         *pSameAs = IsBlankLine(*pp) ? Line_Blank : Line_Different;
+      }
+      else
+      {
+         *pSameAs = Line_Same; // could have been Line_Unknown
+
+         (*pp)++;
+      }
+   }
+}
+
 int
 CountQuoteLevel(const char *string,
@@ -224,9 +251,11 @@
 
    // look at the beginning of this string and count (nested) quoting levels
+   LineResult sameAsNext = Line_Unknown,
+                 sameAsPrev = Line_Unknown;
    int levels = 0;
    for ( const char *c = string; *c != 0 && *c != '\n'; c++, prev++, next++ )
    {
       // skip leading white space
-      for ( int num_white = 0; *c == '\t' || *c == ' '; c++, prev++, next++  )
+      for ( int num_white = 0; *c == '\t' || *c == ' '; c++ )
       {
          if ( ++num_white > max_white )
@@ -235,8 +264,11 @@
             return levels;
          }
+
+         UpdateLineStatus(c, &prev, &sameAsPrev);
+         UpdateLineStatus(c, &next, &sameAsNext);
       }
 
       // skip optional alphanumeric prefix
-      for ( int num_alpha = 0; isalpha((unsigned char)*c); c++, prev++, next++ )
+      for ( int num_alpha = 0; isalpha((unsigned char)*c); c++ )
       {
          if ( ++num_alpha > max_alpha )
@@ -245,4 +277,7 @@
             return levels;
          }
+
+         UpdateLineStatus(c, &prev, &sameAsPrev);
+         UpdateLineStatus(c, &next, &sameAsNext);
       }
 
@@ -253,15 +288,33 @@
       // necessary to catch last line in a numbered list which would otherwise
       // be considered quoted)
-      //
+
+      // first check if we have a quote character at all
       // TODO: make the string of "quoting characters" configurable
       static const char *QUOTE_CHARS = ">|})*";
-      const size_t pos = c - string;
-      if ( !strchr(QUOTE_CHARS, *c) ||
-            (strncmp(string, next - pos, pos + 1) && !IsBlankLine(next + 1)) ||
-             (*prev == *c && strncmp(string, prev - pos, pos)) )
+      if ( !strchr(QUOTE_CHARS, *c) )
+         break;
+
+      // next check if the next line has the same prefix
+      if ( sameAsNext != Line_Different )
+      {
+         // so far it does
+         if ( *next != *c && !IsBlankLine(next) )
+         {
+            // but then it diverges, so this is unlikely to be a quote marker
+            break;
+         }
+      }
+      else // not the same one, but maybe the next line is blank?
+      {
+         if ( !IsBlankLine(next + 1) )
+            break;
+      }
+
+      // finally check the previous line
+      if ( sameAsPrev == Line_Same && *prev != *c )
       {
-         // not quoted (according to our heuristics anyhow)
          break;
       }
+      //else: it's either identical or completely different, both are fine
 
       levels++;



-------------------------------------------------------
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

Reply via email to