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

Modified Files:
        QuoteURL.cpp 
Log Message:
centralized all global quoting data in QuoteData class to make code even simpler; 
store quote markers for different levels separately, this fixes a problem with 
messages where some quoted line are garbled (they're still not shown as quoted but at 
least all other lines are)

Index: QuoteURL.cpp
===================================================================
RCS file: /cvsroot/mahogany/M/src/modules/viewflt/QuoteURL.cpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -b -u -2 -r1.22 -r1.23
--- QuoteURL.cpp        16 Sep 2004 20:51:34 -0000      1.22
+++ QuoteURL.cpp        17 Sep 2004 10:33:54 -0000      1.23
@@ -70,4 +70,46 @@
 
 // ----------------------------------------------------------------------------
+// local classes
+// ----------------------------------------------------------------------------
+
+// this struct is used by CountQuoteLevel() to store global information about
+// the message
+class QuoteData
+{
+public:
+   QuoteData() { levelWrapped = 0; linePrev = NULL; }
+
+   // functions for querying/setting quote prefix for the given (0-based) level
+   bool HasQuoteAtLevel(size_t level) const
+   {
+      return m_quoteAtLevel.size() > level;
+   }
+
+   void SetQuoteAtLevel(size_t level, const String& s)
+   {
+      ASSERT_MSG( level == m_quoteAtLevel.size(),
+                     _T("should set quote prefixes in order") );
+
+      m_quoteAtLevel.push_back(s);
+   }
+
+   const String& GetQuoteAtLevel(size_t level) const
+   {
+      return m_quoteAtLevel[level];
+   }
+
+
+   // pointer to previous line we examined
+   const char *linePrev;
+
+   // set to > 0 if the next line is wrapped tail of this one
+   int levelWrapped;
+
+private:
+   // array of quote markers for all quoting levels we have seen so far
+   wxArrayString m_quoteAtLevel;
+};
+
+// ----------------------------------------------------------------------------
 // private functions
 // ----------------------------------------------------------------------------
@@ -78,18 +120,15 @@
 
     @param string the string to check
-    @param prev the start of previous line or NULL if start of text
     @param max_white max number of white characters before quotation mark
     @param max_alpha max number of A-Z characters before quotation mark
-    @param quote the quoting prefix, empty initially meaning unknown,
-                 should be saved between function calls later
+    @param quoteData global quoting data, should be saved between function
+                     calls
     @return number of quoting levels (0 for unquoted text)
   */
 static int
 CountQuoteLevel(const char *string,
-                const char *prev,
                 int max_white,
                 int max_alpha,
-                bool *nextWrapped,
-                String& quote);
+                QuoteData& quoteData);
 
 /**
@@ -168,8 +207,5 @@
 
    // get the quote level for the line (prev is for CountQuoteLevel() only)
-   size_t GetQuotedLevel(const char *line,
-                         const char *prev,
-                         bool *nextWrapped,
-                         String& quote) const;
+   size_t GetQuotedLevel(const char *line, QuoteData& quote) const;
 
    // get the colour for the given quote level
@@ -238,11 +274,21 @@
 int
 CountQuoteLevel(const char *string,
-                const char *prev,
                 int max_white,
                 int max_alpha,
-                bool *nextWrapped,
-                String& quote)
+                QuoteData& quoteData)
 {
-   *nextWrapped = false;
+   // update the previous line pointer for the next call
+   const char *prev = quoteData.linePrev;
+   quoteData.linePrev = string;
+
+   // check if this line had been already detected as a quoted tail of the
+   // previous one
+   int level = quoteData.levelWrapped;
+   if ( level )
+   {
+      quoteData.levelWrapped = 0;
+      return level;
+   }
+
 
    // find the beginning of the and next line
@@ -263,6 +309,6 @@
    LineResult sameAsNext = Line_Unknown,
               sameAsPrev = Line_Unknown;
-   int levels = 0;
-   for ( const char *c = string; *c != 0 && *c != '\n'; c++ )
+   const char *lastQuote = string;
+   for ( const char *c = string; *c != 0 && *c != '\n'; c++, lastQuote = c )
    {
       // skip leading white space
@@ -272,5 +318,5 @@
          {
             // too much whitespace for this to be a quoted string
-            return levels;
+            return level;
          }
 
@@ -285,5 +331,5 @@
          {
             // prefix too long, not start of the quote
-            return levels;
+            return level;
          }
 
@@ -298,5 +344,5 @@
 
       // first check if we have a quote prefix for this level at all
-      if ( quote.length() <= (size_t)(c - string) )
+      if ( !quoteData.HasQuoteAtLevel(level) )
       {
          // detect the quoting character used, and remember it for the rest of
@@ -316,10 +362,11 @@
             break;
 
-         quote = String(string, c + 1);
+         quoteData.SetQuoteAtLevel(level, String(lastQuote, c + 1));
       }
       else // we have already seen this quoting prefix
       {
-         // check that we have it
-         if ( !quote.StartsWith(String(string, c + 1)) )
+         // check that we have the same prefix
+         if ( wxStrncmp(lastQuote, quoteData.GetQuoteAtLevel(level),
+                           c - lastQuote + 1) != 0 )
             break;
       }
@@ -380,5 +427,5 @@
                else // looks like the next line is indeed our wrapped tail
                {
-                  *nextWrapped = true;
+                  quoteData.levelWrapped = level + 1;
 
                   isQuoted = true;
@@ -401,8 +448,8 @@
          break;
 
-      levels++;
+      level++;
    }
 
-   return levels;
+   return level;
 }
 
@@ -470,17 +517,12 @@
 
 size_t
-QuoteURLFilter::GetQuotedLevel(const char *line,
-                               const char *prev,
-                               bool *nextWrapped,
-                               String& quote) const
+QuoteURLFilter::GetQuotedLevel(const char *line, QuoteData& quoteData) const
 {
    size_t qlevel = CountQuoteLevel
                    (
                      line,
-                     prev,
                      m_options.quotedMaxWhitespace,
                      m_options.quotedMaxAlpha,
-                     nextWrapped,
-                     quote
+                     quoteData
                    );
 
@@ -540,9 +582,7 @@
    size_t level = LEVEL_INVALID;
 
-   bool nextWrapped = false;
-   String quotePrefix;
+   QuoteData quoteData;
 
-   const wxChar *linePrev = NULL,
-                *lineCur = text.c_str();
+   const wxChar *lineCur = text.c_str();
 
    int lenURL;
@@ -552,14 +592,5 @@
       if ( m_options.quotedColourize )
       {
-         // get the level of the current line, unless it is a wrapped tail of
-         // the last line in which case it has the same level
-         if ( nextWrapped )
-         {
-            nextWrapped = false;
-         }
-         else // not wrapped
-         {
-            size_t levelNew =
-               GetQuotedLevel(lineCur, linePrev, &nextWrapped, quotePrefix);
+         size_t levelNew = GetQuotedLevel(lineCur, quoteData);
             if ( levelNew != level )
             {
@@ -568,5 +599,4 @@
             }
          }
-      }
 
       // find the start of the next line
@@ -606,5 +636,4 @@
 
       // go to the next line (skip '\n')
-      linePrev = lineCur;
       lineCur = lineNext + 1;
    }



-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 24. Go here: http://sf.net/ppc_contest.php
_______________________________________________
Mahogany-cvsupdates mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to