OSDN Git Service

PATCH: [ 968285 ] DBCS fixes from Sawanaka
authorPerry Rapp <elsapo@users.sourceforge.net>
Sun, 6 Mar 2005 18:39:52 +0000 (18:39 +0000)
committerPerry Rapp <elsapo@users.sourceforge.net>
Sun, 6 Mar 2005 18:39:52 +0000 (18:39 +0000)
  (continuing editlib portions)
  Src/editlib: batch.cpp crystaleditview.cpp crystaltextview2.cpp cplusplus.cpp
   cregexp.cpp csharp.cpp dcl.cpp filesup.cpp fortran.cpp html.cpp js.cpp
   java.cpp list.cpp pascal.cpp perl.cpp php.cpp python.cpp rexx.cpp rsrc.cpp
   sgml.cpp sh.cpp siod.cpp sql.cpp tcl.cpp tex.cpp xml.cpp

27 files changed:
Src/editlib/batch.cpp
Src/editlib/ccrystaleditview.cpp
Src/editlib/ccrystaltextview2.cpp
Src/editlib/cplusplus.cpp
Src/editlib/cregexp.cpp
Src/editlib/csharp.cpp
Src/editlib/dcl.cpp
Src/editlib/filesup.cpp
Src/editlib/fortran.cpp
Src/editlib/html.cpp
Src/editlib/is.cpp
Src/editlib/java.cpp
Src/editlib/lisp.cpp
Src/editlib/pascal.cpp
Src/editlib/perl.cpp
Src/editlib/php.cpp
Src/editlib/python.cpp
Src/editlib/rexx.cpp
Src/editlib/rsrc.cpp
Src/editlib/sgml.cpp
Src/editlib/sh.cpp
Src/editlib/siod.cpp
Src/editlib/sql.cpp
Src/editlib/tcl.cpp
Src/editlib/tex.cpp
Src/editlib/xml.cpp
Src/readme.txt

index b6a585c..6f84e66 100644 (file)
@@ -660,13 +660,14 @@ ParseLineBatch (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIt
   BOOL bDecIndex = FALSE;
   BOOL bOneWord = TRUE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -713,7 +714,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -724,7 +725,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -742,7 +743,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -766,7 +767,7 @@ out:
             }
           if (dwCookie & COOKIE_EXT_COMMENT)
               continue;
-          if (nLength >= I + 3 && !_tcsnicmp (pszChars + I, _T ("REM"), 3) && (_istspace (pszChars[I + 3]) || nLength == I + 3))
+          if (nLength >= I + 3 && !_tcsnicmp (pszChars + I, _T ("REM"), 3) && (xisspace (pszChars[I + 3]) || nLength == I + 3))
             {
               DEFINE_BLOCK (I, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_COMMENT;
@@ -775,7 +776,7 @@ out:
 
           if (pszChars[I] == ':')
             {
-              if (nLength > I + 2 && !(xisalnum (pszChars[I+1]) || isspace (pszChars[I+1])))
+              if (nLength > I + 2 && !(xisalnum (pszChars[I+1]) || xisspace (pszChars[I+1])))
                 {
                   DEFINE_BLOCK (I, COLORINDEX_COMMENT);
                   dwCookie |= COOKIE_COMMENT;
@@ -785,7 +786,7 @@ out:
               dwCookie |= COOKIE_PREPROCESSOR;
               continue;
             }
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
index 313a6a0..e224767 100644 (file)
@@ -607,7 +607,8 @@ OnEditDeleteBack ()
   else                          // If Caret Not At SOL
 
     {
-      ptCursorPos.x--;          // Decrement Position
+      if (ptCursorPos.x > 1 && m_pTextBuffer->IsMBSTrail (ptCursorPos.y, ptCursorPos.x-1)) ptCursorPos.x--; /* MULTIBYTES */
+          ptCursorPos.x--;          // Decrement Position
 
       //yuyunyi
       if (ptCursorPos.x > 0 && m_pTextBuffer->IsMBSTrail (ptCursorPos.y, ptCursorPos.x))
@@ -1601,7 +1602,7 @@ OnEditOperation (int nAction, LPCTSTR pszText)
           int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y - 1);
           LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y - 1);
           int nPos = 0;
-          while (nPos < nLength && _istspace (pszLineChars[nPos]))
+          while (nPos < nLength && xisspace (pszLineChars[nPos]))
             nPos++;
 
           if (nPos > 0)
@@ -1735,7 +1736,7 @@ OnEditOperation (int nAction, LPCTSTR pszText)
           int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
           LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y );
           int nPos = 0;
-          while (nPos < nLength && _istspace (pszLineChars[nPos]))
+          while (nPos < nLength && xisspace (pszLineChars[nPos]))
             nPos++;
           if (nPos == nLength - 1)
             {
@@ -1780,7 +1781,7 @@ OnEditOperation (int nAction, LPCTSTR pszText)
           int nLength = m_pTextBuffer->GetLineLength (ptCursorPos.y);
           LPCTSTR pszLineChars = m_pTextBuffer->GetLineChars (ptCursorPos.y );
           int nPos = 0;
-          while (nPos < nLength && _istspace (pszLineChars[nPos]))
+          while (nPos < nLength && xisspace (pszLineChars[nPos]))
             nPos++;
           if (ptCursorPos.y > 0 && nPos && nPos == nLength - 1)
             {
@@ -2236,7 +2237,7 @@ OnEditCapitalize ()
       bool bCapitalize = true;
       while (*pszText)
         {
-          if (_istspace (*pszText))
+          if (xisspace (*pszText))
             bCapitalize = true;
           else if (_istalpha (*pszText))
             if (bCapitalize)
@@ -2301,7 +2302,7 @@ OnEditSentence ()
       bool bCapitalize = true;
       while (*pszText)
         {
-          if (!_istspace (*pszText))
+          if (!xisspace (*pszText))
             if (*pszText == _T ('.'))
               {
                 if (pszText[1] && !_istdigit (pszText[1]))
index 2bf5764..af1c78b 100644 (file)
@@ -150,22 +150,24 @@ MoveWordLeft (BOOL bSelect)
 
   LPCTSTR pszChars = GetLineChars (m_ptCursorPos.y);
   int nPos = m_ptCursorPos.x;
-  while (nPos > 0 && _istspace (pszChars[nPos - 1]))
-    nPos--;
+  int nPrevPos;
+  while (nPos > 0 && xisspace (pszChars[nPrevPos = ::CharPrev(pszChars, pszChars + nPos) - pszChars]))
+    nPos = nPrevPos;
 
   if (nPos > 0)
     {
-      nPos--;
+      int nPrevPos = ::CharPrev(pszChars, pszChars + nPos) - pszChars;
+      nPos = nPrevPos;
       if (xisalnum (pszChars[nPos]))
         {
-          while (nPos > 0 && xisalnum (pszChars[nPos - 1]))
-            nPos--;
+          while (nPos > 0 && (xisalnum (pszChars[nPrevPos = ::CharPrev(pszChars, pszChars + nPos) - pszChars])))
+            nPos = nPrevPos;
         }
       else
         {
-          while (nPos > 0 && !xisalnum (pszChars[nPos - 1])
-                && !_istspace (pszChars[nPos - 1]))
-            nPos--;
+          while (nPos > 0 && !xisalnum (pszChars[nPrevPos = ::CharPrev(pszChars, pszChars + nPos) - pszChars])
+                && !xisspace (pszChars[nPrevPos]))
+            nPos = nPrevPos;
         }
     }
 
@@ -208,17 +210,17 @@ MoveWordRight (BOOL bSelect)
   if (xisalnum (pszChars[nPos]))
     {
       while (nPos < nLength && xisalnum (pszChars[nPos]))
-        nPos++;
+        nPos = ::CharNext(pszChars + nPos) - pszChars;
     }
   else
     {
       while (nPos < nLength && !xisalnum (pszChars[nPos])
-            && !_istspace (pszChars[nPos]))
-        nPos++;
+            && !xisspace (pszChars[nPos]))
+        nPos = ::CharNext(pszChars + nPos) - pszChars;
     }
 
-  while (nPos < nLength && _istspace (pszChars[nPos]))
-    nPos++;
+  while (nPos < nLength && xisspace (pszChars[nPos]))
+    nPos = ::CharNext(pszChars + nPos) - pszChars;
 
   m_ptCursorPos.x = nPos;
   m_nIdealCharPos = CalculateActualOffset (m_ptCursorPos.y, m_ptCursorPos.x);
@@ -314,7 +316,7 @@ MoveHome (BOOL bSelect)
        /*ORIGINAL
        int nHomePos = 0;
        *///END SW
-  while (nHomePos < nLength && _istspace (pszChars[nHomePos]))
+  while (nHomePos < nLength && xisspace (pszChars[nHomePos]))
     nHomePos++;
   if (nHomePos == nLength || m_ptCursorPos.x == nHomePos)
                //BEGIN SW
@@ -532,7 +534,7 @@ WordToRight (CPoint pt)
     {
       if (!xisalnum (pszChars[pt.x]))
         break;
-      pt.x++;
+      pt.x += ::CharNext (&pszChars[pt.x]) - &pszChars[pt.x];
     }
   ASSERT_VALIDTEXTPOS (pt);
   return pt;
@@ -543,11 +545,13 @@ WordToLeft (CPoint pt)
 {
   ASSERT_VALIDTEXTPOS (pt);
   LPCTSTR pszChars = GetLineChars (pt.y);
+  int nPrevX = pt.x;
   while (pt.x > 0)
     {
-      if (!xisalnum (pszChars[pt.x - 1]))
+      nPrevX -= &pszChars[pt.x] - ::CharPrev (pszChars, &pszChars[pt.x]);
+      if (!xisalnum (pszChars[nPrevX]))
         break;
-      pt.x--;
+      pt.x = nPrevX;
     }
   ASSERT_VALIDTEXTPOS (pt);
   return pt;
index b2dc663..0716ef2 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -267,13 +268,14 @@ ParseLineC (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems)
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -288,7 +290,7 @@ ParseLineC (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems)
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -318,7 +320,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -329,7 +331,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -340,8 +342,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -350,9 +352,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -360,9 +362,9 @@ out:
       //  Preprocessor directive #....
       if (dwCookie & COOKIE_PREPROCESSOR)
         {
-          if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+          if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
             {
-              DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+              DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_EXT_COMMENT;
             }
           continue;
@@ -378,16 +380,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -403,7 +405,7 @@ out:
               dwCookie |= COOKIE_PREPROCESSOR;
               continue;
             }
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -411,7 +413,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -438,7 +440,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -479,7 +481,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -495,7 +497,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 99c4c0a..683e418 100644 (file)
 
 //#define DEBUG
 
+#ifdef _UNICODE
+#define mytcsnextc(p) (*p)
+#else
+__inline unsigned int mytcsnextc(LPCSTR p) {
+       int ch = 0;
+       if (_ismbblead((unsigned char)*p))
+               ch = ((unsigned char)*p++<<8);
+       ch += (unsigned char)*p;
+       return ch;
+}
+#endif
+
 static int RegCount = 0;
 
 #ifdef DEBUG
@@ -40,20 +52,33 @@ static  RxNode *NewNode(int aWhat) {
     return N;
 }
 
-static RxNode *NewChar(TCHAR Ch) {
+static RxNode *NewChar(unsigned int Ch) {
     RxNode *A = NewNode(RE_CHAR);
 
     if (A) {
-        A->fChar = (LPTSTR) malloc(1);
+#ifdef _UNICODE
+        A->fChar = (LPTSTR) malloc(2);
         A->fLen = 1;
         A->fChar[0] = Ch;
+#else
+        if (Ch > 0xff) {
+            A->fChar = (LPTSTR) malloc(2);
+            A->fLen = 2;
+            A->fChar[0] = (unsigned char)(Ch >> 8);
+            A->fChar[1] = (unsigned char)(Ch & 0xff);
+        } else {
+            A->fChar = (LPTSTR) malloc(1);
+            A->fLen = 1;
+            A->fChar[0] = (unsigned char)Ch;
+        }
+#endif
     }
     return A;
 }
 
 static RxNode *NewEscape(LPCTSTR *const Regexp) {
-    TCHAR Ch = **Regexp;
-    ++*Regexp;
+    unsigned int Ch = mytcsnextc(*Regexp);
+    *Regexp = _tcsinc(*Regexp);
     switch (Ch) {
       case 0: return 0;
       case _T('a'): Ch = _T('\a'); break;
@@ -132,7 +157,7 @@ static RxNode *NewEscape(LPCTSTR *const Regexp) {
 }
 
 
-#define NNN 32        // 8 * 32 = 256 (match set)
+#define NNN 8192        // 8 * 8192 = 65536 (match set)
 
 #ifdef _UNICODE
 #define SETOP(set,n) \
@@ -142,7 +167,7 @@ static RxNode *NewEscape(LPCTSTR *const Regexp) {
 #else // _UNICODE
 #define SETOP(set,n) \
     do { \
-      set[(unsigned char)(n) >> 3] |= (unsigned char)(1 << ((unsigned char)(n) & 7)); \
+      set[(unsigned int)(n) >> 3] |= (unsigned char)(1 << ((unsigned char)(n) & 7)); \
     } while (0)
 #endif // _UNICODE
 
@@ -158,7 +183,7 @@ static RxNode *NewSet(LPCTSTR * const Regexp) {
 #ifdef _UNICODE
     TCHAR Ch, C1 = 0, C2 = 0;
 #else // _UNICODE
-    unsigned char Ch, C1 = 0, C2 = 0;
+    unsigned int Ch, C1 = 0, C2 = 0;
 #endif // _UNICODE
     int doset = 0;
 
@@ -171,7 +196,9 @@ static RxNode *NewSet(LPCTSTR * const Regexp) {
     c = 0;
 
     while (**Regexp) {
-        switch (Ch = *((*Regexp)++)) {
+        Ch = mytcsnextc(*Regexp);
+        *Regexp = _tcsinc(*Regexp);
+        switch (Ch) {
           case _T(']'):
             if (doset == 1) return 0;
             {
@@ -183,7 +210,9 @@ static RxNode *NewSet(LPCTSTR * const Regexp) {
                 return N;
             }
           case _T('\\'):
-            switch (Ch = *((*Regexp)++)) {
+            Ch = mytcsnextc(*Regexp);
+            *Regexp = _tcsinc(*Regexp);
+            switch (Ch) {
               case 0: return 0;
               case _T('a'): Ch = _T('\a'); break;
               case _T('b'): Ch = _T('\b'); break;
@@ -552,8 +581,8 @@ static RxNode *RxComp(LPCTSTR *Regexp) {
         case _T('>'): CHECK(AddNode(&F, &N, NewNode(RE_ATEOW)));     break;
         default:
             --*Regexp;
-            CHECK(AddNode(&F, &N, NewChar(**Regexp)));
-            ++*Regexp;
+            CHECK(AddNode(&F, &N, NewChar(mytcsnextc(*Regexp))));
+            *Regexp = _tcsinc(*Regexp);
             break;
         }
     }
@@ -628,47 +657,47 @@ int RxMatch(RxNode *rx) {
             break;
         case RE_ANY:
             if (rex == eop) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_WSPACE:
             if (rex == eop) return 0;
             if (*rex != _T(' ') && *rex != _T('\n') && *rex != _T('\r') && *rex != _T('\t')) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_NWSPACE:
             if (rex == eop) return 0;
             if (*rex == _T(' ') || *rex == _T('\n') || *rex == _T('\r') || *rex == _T('\t')) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_WORD:
             if (rex == eop) return 0;
             if (!_istalnum(*rex)) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_NWORD:
             if (rex == eop) return 0;
             if (_istalnum(*rex)) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_DIGIT:
             if (rex == eop) return 0;
             if (!_istdigit(*rex)) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_NDIGIT:
             if (rex == eop) return 0;
             if (_istdigit(*rex)) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_UPPER:
             if (rex == eop) return 0;
             if (!_istupper(*rex)) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_LOWER:
             if (rex == eop) return 0;
             if (!_istlower(*rex)) return 0;
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_ATBOW:
             if (rex >= eop) return 0;
@@ -688,8 +717,8 @@ int RxMatch(RxNode *rx) {
                 if (*n->fChar != *rex) return 0;
                 if (memcmp(rex, n->fChar, n->fLen) != 0) return 0;
             } else {
-                for (int i = 0; i < n->fLen; i++)
-                    if (_totupper(rex[i]) != _totupper(n->fChar[i]))
+                for (int i = 0; i < n->fLen; i+= _tcsinc(&rex[i]) - &rex[i])
+                    if (_totupper(mytcsnextc(&rex[i])) != _totupper(mytcsnextc(&n->fChar[i])))
                         return 0;
             }
             rex += n->fLen;
@@ -699,18 +728,24 @@ int RxMatch(RxNode *rx) {
 #ifdef _UNICODE
             if ((n->fChar[(TCHAR)(*rex) >> 3] & (1 << ((TCHAR)(*rex) & 7))) == 0) return 0;
 #else // _UNICODE
-            if ((n->fChar[(unsigned char)(*rex) >> 3] & (1 << ((unsigned char)(*rex) & 7))) == 0) return 0;
+            {
+            unsigned int ch = mytcsnextc(rex);
+            if ((n->fChar[ch >> 3] & (1 << ((unsigned char)(ch) & 7))) == 0) return 0;
+            }
 #endif // _UNICODE
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_NOTINSET:
             if (rex == eop) return 0;
 #ifdef _UNICODE
             if (n->fChar[(TCHAR)(*rex) >> 3] & (1 << ((TCHAR)(*rex) & 7))) return 0;
 #else // _UNICODE
-            if (n->fChar[(unsigned char)(*rex) >> 3] & (1 << ((unsigned char)(*rex) & 7))) return 0;
+            {
+            unsigned int ch = mytcsnextc(rex);
+            if (n->fChar[ch >> 3] & (1 << ((unsigned char)(ch) & 7))) return 0;
+            }
 #endif // _UNICODE
-            rex++;
+            rex = _tcsinc(rex);
             break;
         case RE_JUMP:
             n = n->fPtr;
@@ -824,24 +859,25 @@ int RxExec(RxNode *Regexp, LPCTSTR Data, int Len, LPCTSTR Start, RxMatchRes *Mat
         if (flags & RX_CASE) {
             while (1) {
                 while (Start < eop && *Start != Ch)
-                    Start++;
+                    Start = _tcsinc(Start);
                 if (Start == eop)
                     break;
                 if (RxTry(Regexp, Start))
                     return 1;
-                if (++Start == eop)
+                if ((Start = _tcsinc(Start)) == eop)
                     break;
             }
         } else {
             Ch = (TCHAR)_totupper(Ch);
             while (1) {
-                while (Start < eop && (TCHAR) _totupper(*Start) != Ch)
-                    Start++;
+                while (Start < eop && (TCHAR) _totupper(*Start) != Ch) {
+                    Start = _tcsinc(Start);
+                }
                 if (Start == eop)
                     break;
                 if (RxTry(Regexp, Start))
                     return 1;
-                if (++Start == eop)
+                if ((Start = _tcsinc(Start)) == eop)
                     break;
             }
         }
@@ -849,7 +885,7 @@ int RxExec(RxNode *Regexp, LPCTSTR Data, int Len, LPCTSTR Start, RxMatchRes *Mat
     default:         // (slow)
         do {
             if (RxTry(Regexp, Start)) return 1;
-        } while (Start++ < eop);
+        } while ((Start = _tcsinc(Start)) < eop);
         break;
     }
     return 0;
index 9642c70..d9ffa6c 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -191,13 +192,14 @@ ParseLineCSharp (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualI
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -212,7 +214,7 @@ ParseLineCSharp (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualI
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -242,7 +244,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -253,7 +255,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -264,8 +266,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -274,9 +276,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -284,9 +286,9 @@ out:
       //  Preprocessor directive #....
       if (dwCookie & COOKIE_PREPROCESSOR)
         {
-          if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+          if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
             {
-              DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+              DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_EXT_COMMENT;
             }
           continue;
@@ -302,16 +304,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -327,7 +329,7 @@ out:
               dwCookie |= COOKIE_PREPROCESSOR;
               continue;
             }
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -335,7 +337,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -358,7 +360,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -395,7 +397,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -411,7 +413,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 96227af..de41146 100644 (file)
@@ -194,13 +194,14 @@ ParseLineDcl (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -241,7 +242,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -252,7 +253,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -263,8 +264,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -273,9 +274,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -290,16 +291,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -309,7 +310,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -348,7 +349,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '{' || pszChars[j] == ':')
                             {
@@ -361,7 +362,7 @@ out:
                     {
                       for (int j = nIdentBegin; --j >= 0;)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == ':')
                                 {
@@ -407,7 +408,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '{' || pszChars[j] == ':')
                     {
@@ -420,7 +421,7 @@ out:
             {
               for (int j = nIdentBegin; --j >= 0;)
                 {
-                  if (!_istspace (pszChars[j]))
+                  if (!xisspace (pszChars[j]))
                     {
                       if (pszChars[j] == ':')
                         {
index 1c16038..7f74aef 100644 (file)
@@ -45,7 +45,11 @@ GetExtPosition (LPCTSTR pszString)
   do
     if ((test = sString.GetAt (--posit)) == _T ('.'))
       return posit;
+#ifdef _UNICODE
   while (posit && test != _T ('\\') && test != _T (':'));
+#else
+  while (posit && (test != _T ('\\') || _ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) && test != _T (':'));
+#endif
   return len;
 }
 
@@ -86,7 +90,11 @@ GetNamePosition (LPCTSTR pszString)
   int posit = sString.GetLength ();
   TCHAR test;
   do
+#ifdef _UNICODE
     if ((test = sString.GetAt (--posit)) == _T ('\\') || test == _T (':'))
+#else
+    if (((test = sString.GetAt (--posit)) == _T ('\\') && !_ismbstrail((unsigned char *)pszString, (unsigned char *)pszString + posit)) || test == _T (':'))
+#endif
       return posit + 1;
   while (posit);
   return posit;
@@ -103,7 +111,11 @@ GetPath (const CString & sString, BOOL bClose /*= FALSE*/ )
 
   TCHAR test = sString.GetAt (posit - 1);
 
+#ifdef _UNICODE
   if (test == _T (':') || test == _T ('\\') && (posit == 1 || posit != 1 && sString.GetAt (posit - 2) == _T (':')))
+#else
+  if (test == _T (':') || (test == _T ('\\') && !_ismbstrail((unsigned char *)(LPCTSTR)sString, (unsigned char *)(LPCTSTR)sString + posit)) && (posit == 1 || posit != 1 && sString.GetAt (posit - 2) == _T (':')))
+#endif
     return sString.Left (posit);
   return sString.Left (bClose ? posit : test == _T (':') ? posit : posit - 1);
 }
index 8ec544a..0c034d8 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -307,13 +308,14 @@ ParseLineFortran (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActual
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -324,7 +326,7 @@ ParseLineFortran (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActual
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -354,7 +356,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -365,7 +367,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -390,7 +392,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -400,7 +402,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -408,7 +410,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -444,7 +446,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index e91326b..cc2853f 100644 (file)
@@ -454,13 +454,14 @@ ParseLineHtml (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -509,7 +510,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -520,7 +521,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -531,7 +532,7 @@ out:
       //  Extended comment <!--....-->
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          if (I > 1 && pszChars[I] == '>' && pszChars[I - 1] == '-' && pszChars[I - 2] == '-')
+          if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -542,7 +543,7 @@ out:
       //  Extended comment <?....?>
       if (dwCookie & COOKIE_EXT_USER1)
         {
-          if (I > 0 && pszChars[I] == '>' && (pszChars[I - 1] == '?' || pszChars[I - 1] == '%'))
+          if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
             {
               dwCookie &= ~COOKIE_EXT_USER1;
               bRedefineBlock = TRUE;
@@ -561,7 +562,7 @@ out:
       if ((dwCookie & COOKIE_PREPROCESSOR) && pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -580,7 +581,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -655,7 +656,7 @@ next:
           //  User1 end: ?>
           if (dwCookie & COOKIE_EXT_USER1)
             {
-              if (I > 0 && pszChars[I] == '>' && (pszChars[I - 1] == '?' || pszChars[I - 1] == '%'))
+              if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
                 {
                   dwCookie &= ~COOKIE_EXT_USER1;
                   nIdentBegin = -1;
@@ -723,7 +724,7 @@ next:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -760,7 +761,7 @@ next:
   //  User1 end: ?>
   if (dwCookie & COOKIE_EXT_USER1)
     {
-      if (I > 0 && pszChars[I] == '>' && (pszChars[I - 1] == '?' || pszChars[I - 1] == '%'))
+      if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
         {
           dwCookie &= ~COOKIE_EXT_USER1;
           nIdentBegin = -1;
index 197d84f..1ff9c8b 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -500,13 +501,14 @@ ParseLineIS (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -521,7 +523,7 @@ ParseLineIS (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -551,7 +553,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -562,7 +564,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -573,8 +575,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -583,9 +585,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -593,9 +595,9 @@ out:
       //  Preprocessor directive #....
       if (dwCookie & COOKIE_PREPROCESSOR)
         {
-          if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+          if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
             {
-              DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+              DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_EXT_COMMENT;
             }
           continue;
@@ -611,16 +613,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -636,7 +638,7 @@ out:
               dwCookie |= COOKIE_PREPROCESSOR;
               continue;
             }
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -644,7 +646,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -675,7 +677,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -720,7 +722,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -736,7 +738,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 1610889..13aa9e7 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -153,13 +154,14 @@ ParseLineJava (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -174,7 +176,7 @@ ParseLineJava (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -204,7 +206,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -215,7 +217,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -226,8 +228,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -236,9 +238,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -246,9 +248,9 @@ out:
       //  Preprocessor directive #....
       if (dwCookie & COOKIE_PREPROCESSOR)
         {
-          if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+          if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
             {
-              DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+              DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_EXT_COMMENT;
             }
           continue;
@@ -264,16 +266,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -289,7 +291,7 @@ out:
               dwCookie |= COOKIE_PREPROCESSOR;
               continue;
             }
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -297,7 +299,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -320,7 +322,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -357,7 +359,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -373,7 +375,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index c5f51a4..7932d45 100644 (file)
@@ -331,13 +331,14 @@ ParseLineLisp (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   int nIdentBegin = -1;
   BOOL bDefun = FALSE;
 
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -378,7 +379,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -389,7 +390,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -400,8 +401,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == ';' && pszChars[I - 1] == '|')
-          if ((I > 1 && pszChars[I] == ';' && pszChars[I - 1] == '|' /*&& pszChars[I - 2] != ';'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == ';' && pszChars[I - 1] == '|'))
+          // if (I > 0 && pszChars[I] == ';' && pszChars[nPrevI] == '|')
+          if ((I > 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != ';'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -410,7 +411,7 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] != '|' && pszChars[I - 1] == ';')
+      if (I > 0 && pszChars[I] != '|' && pszChars[nPrevI] == ';')
         {
           DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
@@ -427,14 +428,14 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '|' && pszChars[I - 1] == ';')
+      if (I > 0 && pszChars[I] == '|' && pszChars[nPrevI] == ';')
         {
           DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
@@ -446,7 +447,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -483,7 +484,7 @@ out:
                     {
                       for (int j = nIdentBegin; --j >= 0;)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == '(')
                                 {
@@ -497,7 +498,7 @@ out:
                     {
                       for (int j = I; j >= 0; j--)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == '(')
                                 {
@@ -541,7 +542,7 @@ out:
             {
               for (int j = nIdentBegin; --j >= 0;)
                 {
-                  if (!_istspace (pszChars[j]))
+                  if (!xisspace (pszChars[j]))
                     {
                       if (pszChars[j] == '(')
                         {
@@ -555,7 +556,7 @@ out:
             {
               for (int j = I; j >= 0; j--)
                 {
-                  if (!_istspace (pszChars[j]))
+                  if (!xisspace (pszChars[j]))
                     {
                       if (pszChars[j] == '(')
                         {
index e83588b..44f1827 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -154,13 +155,14 @@ ParseLinePascal (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualI
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -171,7 +173,7 @@ ParseLinePascal (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualI
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -201,7 +203,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -212,7 +214,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -223,8 +225,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == ')' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == ')' && pszChars[I - 1] == '*' && pszChars[I - 2] != '(') || (I == 1 && pszChars[I] == ')' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == ')' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == ')' && pszChars[nPrevI] == '*' && *::CharPrev(pszChars, pszChars + nPrevI) != '(') || (I == 1 && pszChars[I] == ')' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -243,9 +245,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -260,16 +262,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '(')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '(')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           continue;
         }
@@ -283,7 +285,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -291,7 +293,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -314,7 +316,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -351,7 +353,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -367,7 +369,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_EXT_COMMENT2);
   return dwCookie;
 }
index a412e8c..59557f0 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -324,13 +325,14 @@ ParseLinePerl (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -341,7 +343,7 @@ ParseLinePerl (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -371,7 +373,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -382,7 +384,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -407,7 +409,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -417,7 +419,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -425,7 +427,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -448,7 +450,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -485,7 +487,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -501,7 +503,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 3a949d2..9175293 100644 (file)
@@ -545,13 +545,14 @@ ParseLinePhp (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -600,7 +601,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -611,7 +612,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -624,7 +625,7 @@ out:
         {
           if (dwCookie & COOKIE_EXT_USER1)
             {
-              if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+              if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
                 {
                   dwCookie &= ~COOKIE_EXT_COMMENT;
                   bRedefineBlock = TRUE;
@@ -633,7 +634,7 @@ out:
             }
           else
             {
-              if (I > 1 && pszChars[I] == '>' && pszChars[I - 1] == '-' && pszChars[I - 2] == '-')
+              if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
                 {
                   dwCookie &= ~COOKIE_EXT_COMMENT;
                   bRedefineBlock = TRUE;
@@ -642,9 +643,9 @@ out:
           continue;
         }
 
-      if ((dwCookie & COOKIE_EXT_USER1) && I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if ((dwCookie & COOKIE_EXT_USER1) && I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -659,7 +660,7 @@ out:
       //  Extended comment <?....?>
       if (dwCookie & COOKIE_EXT_USER1)
         {
-          if (I > 0 && pszChars[I] == '>' && (pszChars[I - 1] == '?' || pszChars[I - 1] == '%'))
+          if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
             {
               dwCookie &= ~COOKIE_EXT_USER1;
               bRedefineBlock = TRUE;
@@ -678,7 +679,7 @@ out:
       if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -688,9 +689,9 @@ out:
 
       if (dwCookie & COOKIE_EXT_USER1)
         {
-          if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+          if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
             {
-              DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+              DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_EXT_COMMENT;
               bWasCommentStart = TRUE;
               continue;
@@ -711,7 +712,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -775,7 +776,7 @@ out:
 
                       for (int j = I; j < nLength; j++)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == '(')
                                 {
@@ -833,7 +834,7 @@ next:
           //  User1 end: ?>
           if (dwCookie & COOKIE_EXT_USER1)
             {
-              if (I > 0 && pszChars[I] == '>' && (pszChars[I - 1] == '?' || pszChars[I - 1] == '%'))
+              if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
                 {
                   dwCookie &= ~COOKIE_EXT_USER1;
                   nIdentBegin = -1;
@@ -920,7 +921,7 @@ next:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -959,7 +960,7 @@ next:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -996,7 +997,7 @@ next:
   //  User1 end: ?>
   if (dwCookie & COOKIE_EXT_USER1)
     {
-      if (I > 0 && pszChars[I] == '>' && (pszChars[I - 1] == '?' || pszChars[I - 1] == '%'))
+      if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
         {
           dwCookie &= ~COOKIE_EXT_USER1;
           nIdentBegin = -1;
index 99b119c..5f662fe 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -242,13 +243,14 @@ ParseLinePython (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualI
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -259,7 +261,7 @@ ParseLinePython (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualI
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -289,7 +291,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -300,7 +302,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -325,7 +327,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -335,7 +337,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -343,7 +345,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -374,7 +376,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -419,7 +421,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -435,7 +437,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 6494762..443b4fc 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -181,13 +182,14 @@ ParseLineRexx (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -198,7 +200,7 @@ ParseLineRexx (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -228,7 +230,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -239,7 +241,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -250,8 +252,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -260,9 +262,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -277,16 +279,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -296,7 +298,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -304,7 +306,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -331,7 +333,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -372,7 +374,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -388,7 +390,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 3548d4d..0416849 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -245,13 +246,14 @@ ParseLineRsrc (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -266,7 +268,7 @@ ParseLineRsrc (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -296,7 +298,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -307,7 +309,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || pszChars[I - 1] != '\\'))
+          if (pszChars[I] == '\'' && (I == 0 || pszChars[nPrevI] != '\\'))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -318,8 +320,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -328,9 +330,9 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
           break;
         }
@@ -338,9 +340,9 @@ out:
       //  Preprocessor directive #....
       if (dwCookie & COOKIE_PREPROCESSOR)
         {
-          if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+          if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
             {
-              DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+              DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
               dwCookie |= COOKIE_EXT_COMMENT;
             }
           continue;
@@ -356,16 +358,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -381,7 +383,7 @@ out:
               dwCookie |= COOKIE_PREPROCESSOR;
               continue;
             }
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -389,7 +391,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -416,7 +418,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -457,7 +459,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -473,7 +475,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index f21ffff..86e5f9e 100644 (file)
@@ -286,13 +286,14 @@ ParseLineSgml (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -337,7 +338,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -348,7 +349,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -359,7 +360,7 @@ out:
       //  Extended comment <!--....-->
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          if (I > 1 && pszChars[I] == '>' && pszChars[I - 1] == '-' && pszChars[I - 2] == '-')
+          if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -370,7 +371,7 @@ out:
       //  Extended comment <?....?>
       if (dwCookie & COOKIE_EXT_USER1)
         {
-          if (I > 0 && pszChars[I] == '>' && pszChars[I - 1] == '?')
+          if (I > 0 && pszChars[I] == '>' && pszChars[nPrevI] == '?')
             {
               dwCookie &= ~COOKIE_EXT_USER1;
               bRedefineBlock = TRUE;
@@ -388,7 +389,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -406,7 +407,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
index 70d8cb4..680995f 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -149,13 +150,14 @@ ParseLineSh (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -166,7 +168,7 @@ ParseLineSh (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItems
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -196,7 +198,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -207,7 +209,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -232,7 +234,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -242,7 +244,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -250,7 +252,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (*::CharNext(pszChars + I))))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -277,7 +279,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -318,7 +320,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -334,7 +336,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 68d5cc2..a664447 100644 (file)
@@ -409,13 +409,14 @@ ParseLineSiod (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualIte
   int nIdentBegin = -1;
   BOOL bDefun = FALSE;
 
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -456,7 +457,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -467,7 +468,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -478,8 +479,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == ';' && pszChars[I - 1] == '|')
-          if ((I > 1 && pszChars[I] == ';' && pszChars[I - 1] == '|' /*&& pszChars[I - 2] != ';'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == ';' && pszChars[I - 1] == '|'))
+          // if (I > 0 && pszChars[I] == ';' && pszChars[nPrevI] == '|')
+          if ((I > 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != ';'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == ';' && pszChars[nPrevI] == '|'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -488,7 +489,7 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] != '|' && pszChars[I - 1] == ';')
+      if (I > 0 && pszChars[I] != '|' && pszChars[nPrevI] == ';')
         {
           DEFINE_BLOCK (I, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
@@ -505,16 +506,16 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '|' && pszChars[I - 1] == ';')
+      if (I > 0 && pszChars[I] == '|' && pszChars[nPrevI] == ';')
         {
-          DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
+          DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
           bWasCommentStart = TRUE;
           continue;
@@ -524,7 +525,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -569,7 +570,7 @@ out:
                     {
                       for (int j = nIdentBegin; --j >= 0;)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == '(')
                                 {
@@ -583,7 +584,7 @@ out:
                     {
                       for (int j = I; j >= 0; j--)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == '(')
                                 {
@@ -635,7 +636,7 @@ out:
             {
               for (int j = nIdentBegin; --j >= 0;)
                 {
-                  if (!_istspace (pszChars[j]))
+                  if (!xisspace (pszChars[j]))
                     {
                       if (pszChars[j] == '(')
                         {
@@ -649,7 +650,7 @@ out:
             {
               for (int j = I; j >= 0; j--)
                 {
-                  if (!_istspace (pszChars[j]))
+                  if (!xisspace (pszChars[j]))
                     {
                       if (pszChars[j] == '(')
                         {
index 18bc360..3d1fad5 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -141,13 +142,14 @@ ParseLineSql (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
   BOOL bWasCommentStart = FALSE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -158,7 +160,7 @@ ParseLineSql (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -188,7 +190,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -199,7 +201,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -210,8 +212,8 @@ out:
       //  Extended comment /*....*/
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          // if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '*')
-          if ((I > 1 && pszChars[I] == '/' && pszChars[I - 1] == '*' /*&& pszChars[I - 2] != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[I - 1] == '*'))
+          // if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*')
+          if ((I > 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*' /*&& *::CharPrev(pszChars, pszChars + nPrevI) != '/'*/ && !bWasCommentStart) || (I == 1 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -220,7 +222,7 @@ out:
           continue;
         }
 
-      if (I > 0 && pszChars[I] == '/' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/')
         {
           DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_COMMENT;
@@ -237,14 +239,14 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
               continue;
             }
         }
-      if (I > 0 && pszChars[I] == '*' && pszChars[I - 1] == '/')
+      if (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/')
         {
           DEFINE_BLOCK (I - 1, COLORINDEX_COMMENT);
           dwCookie |= COOKIE_EXT_COMMENT;
@@ -256,7 +258,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -264,7 +266,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -291,7 +293,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -332,7 +334,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -348,7 +350,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index 308c944..93d7073 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "stdafx.h"
 #include "ccrystaltextview.h"
+#include "ccrystaltextbuffer.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -116,13 +117,14 @@ ParseLineTcl (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -133,7 +135,7 @@ ParseLineTcl (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
             }
           else
             {
-              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (pszChars[nPos - 1]) && !xisalpha (pszChars[nPos + 1])))
+              if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
                 {
                   DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
                 }
@@ -163,7 +165,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -174,7 +176,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -199,7 +201,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -209,7 +211,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -217,7 +219,7 @@ out:
         continue;               //  We don't need to extract keywords,
       //  for faster parsing skip the rest of loop
 
-      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[I - 1]) && !xisalpha (pszChars[I + 1])))
+      if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
         {
           if (nIdentBegin == -1)
             nIdentBegin = I;
@@ -240,7 +242,7 @@ out:
 
                   for (int j = I; j < nLength; j++)
                     {
-                      if (!_istspace (pszChars[j]))
+                      if (!xisspace (pszChars[j]))
                         {
                           if (pszChars[j] == '(')
                             {
@@ -277,7 +279,7 @@ out:
 
           for (int j = I; j < nLength; j++)
             {
-              if (!_istspace (pszChars[j]))
+              if (!xisspace (pszChars[j]))
                 {
                   if (pszChars[j] == '(')
                     {
@@ -293,7 +295,7 @@ out:
         }
     }
 
-  if (pszChars[nLength - 1] != '\\')
+  if (pszChars[nLength - 1] != '\\' || m_pTextBuffer->IsMBSTrail(nLineIndex, nLength - 1))
     dwCookie &= COOKIE_EXT_COMMENT;
   return dwCookie;
 }
index e72521b..796a1cb 100644 (file)
@@ -937,14 +937,14 @@ ParseLineTex (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -985,7 +985,7 @@ out:
       //  String constant "...."
       if (dwCookie & COOKIE_STRING)
         {
-          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_STRING;
               bRedefineBlock = TRUE;
@@ -996,7 +996,7 @@ out:
       //  Char constant '..'
       if (dwCookie & COOKIE_CHAR)
         {
-          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[I - 1] != '\\' || I >= 2 && (pszChars[I - 1] != '\\' || pszChars[I - 1] == '\\' && pszChars[I - 2] == '\\')))
+          if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || pszChars[nPrevI] == '\\' && *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
             {
               dwCookie &= ~COOKIE_CHAR;
               bRedefineBlock = TRUE;
@@ -1021,7 +1021,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
@@ -1031,7 +1031,7 @@ out:
 
       if (bFirstChar)
         {
-          if (!_istspace (pszChars[I]))
+          if (!xisspace (pszChars[I]))
             bFirstChar = FALSE;
         }
 
@@ -1068,7 +1068,7 @@ out:
                     {
                       for (int j = I; j >= 0; j--)
                         {
-                          if (!_istspace (pszChars[j]))
+                          if (!xisspace (pszChars[j]))
                             {
                               if (pszChars[j] == '$')
                                 {
@@ -1112,7 +1112,7 @@ out:
             {
               for (int j = I; j >= 0; j--)
                 {
-                  if (!_istspace (pszChars[j]))
+                  if (!xisspace (pszChars[j]))
                     {
                       if (pszChars[j] == '$')
                         {
index 783d491..b3ca306 100644 (file)
@@ -255,13 +255,14 @@ ParseLineXml (DWORD dwCookie, int nLineIndex, TEXTBLOCK * pBuf, int &nActualItem
   BOOL bRedefineBlock = TRUE;
   BOOL bDecIndex = FALSE;
   int nIdentBegin = -1;
-  for (int I = 0;; I++)
+  int nPrevI = -1;
+  for (int I = 0;; nPrevI = I, I = ::CharNext(pszChars+I) - pszChars)
     {
       if (bRedefineBlock)
         {
           int nPos = I;
           if (bDecIndex)
-            nPos--;
+            nPos = nPrevI;
           if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
             {
               DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
@@ -328,7 +329,7 @@ out:
       //  Extended comment <!--....-->
       if (dwCookie & COOKIE_EXT_COMMENT)
         {
-          if (I > 1 && pszChars[I] == '>' && pszChars[I - 1] == '-' && pszChars[I - 2] == '-')
+          if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
             {
               dwCookie &= ~COOKIE_EXT_COMMENT;
               bRedefineBlock = TRUE;
@@ -339,7 +340,7 @@ out:
       //  Extended comment <?....?>
       if (dwCookie & COOKIE_EXT_USER1)
         {
-          if (I > 0 && pszChars[I] == '>' && pszChars[I - 1] == '?')
+          if (I > 0 && pszChars[I] == '>' && pszChars[nPrevI] == '?')
             {
               dwCookie &= ~COOKIE_EXT_USER1;
               bRedefineBlock = TRUE;
@@ -357,7 +358,7 @@ out:
       if (pszChars[I] == '\'')
         {
           // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
-          if (!I || !xisalnum (pszChars[I - 1]))
+          if (!I || !xisalnum (pszChars[nPrevI]))
             {
               DEFINE_BLOCK (I, COLORINDEX_STRING);
               dwCookie |= COOKIE_CHAR;
index d9423ec..6d0761a 100644 (file)
@@ -5,6 +5,12 @@
   Add 0,0,0x1 to any FONT line lacking it, for all DIALOGEX dialogs
   Src: Merge.rc
   Languages: Merge*.rc
+ PATCH: [ 968285 ] DBCS fixes from Sawanaka
+  (continuing editlib portions)
+  Src/editlib: batch.cpp crystaleditview.cpp crystaltextview2.cpp cplusplus.cpp
+   cregexp.cpp csharp.cpp dcl.cpp filesup.cpp fortran.cpp html.cpp js.cpp
+   java.cpp list.cpp pascal.cpp perl.cpp php.cpp python.cpp rexx.cpp rsrc.cpp
+   sgml.cpp sh.cpp siod.cpp sql.cpp tcl.cpp tex.cpp xml.cpp
 
 2005-03-05 Perry
  Rename CDirFrame::SetFilter to CDirFrame::SetFilterStatusDisplay for easier greps.