OSDN Git Service

Merge branch 'master' of https://github.com/winmerge/winmerge into jp
[winmerge-jp/winmerge-jp.git] / Externals / crystaledit / editlib / parsers / html.cpp
index 027b6bb..5da5701 100644 (file)
 #define new DEBUG_NEW
 #endif
 
+static void AdjustCharPosInTextBlocks(CrystalLineParser::TEXTBLOCK* pBuf, int startBlock, int endBlock, int offset)
+{
+  for (int i = startBlock; i <= endBlock; ++i)
+    pBuf[i].m_nCharPos += offset;
+}
+
 unsigned
 CrystalLineParser::ParseLineHtmlEx (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems, int nEmbeddedLanguage)
 {
   if (nLength == 0)
-    return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1|COOKIE_ELEMENT|COOKIE_BLOCK_SCRIPT|COOKIE_BLOCK_STYLE);
+    return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1|COOKIE_ELEMENT|COOKIE_BLOCK_SCRIPT|COOKIE_BLOCK_STYLE|COOKIE_EXT_DEFINITION|COOKIE_EXT_VALUE);
 
   bool bRedefineBlock = true;
   if (!(dwCookie & COOKIE_ELEMENT))
@@ -91,8 +97,11 @@ out:
           if (dwCookie & COOKIE_BLOCK_SCRIPT)
             {
               const TCHAR *pszEnd = _tcsstr(pszChars + I, _T("</script>"));
-              int nextI = pszEnd ? (pszEnd - pszChars) : nLength;
-              dwCookie = ParseLineJava(dwCookie & ~COOKIE_BLOCK_SCRIPT, pszChars + I, nextI - I, pBuf, nActualItems);
+              int nextI = pszEnd ? static_cast<int>(pszEnd - pszChars) : nLength;
+              int nActualItemsEmbedded = 0;
+              dwCookie = ParseLineJavaScript(dwCookie & ~COOKIE_BLOCK_SCRIPT, pszChars + I, nextI - I, pBuf + nActualItems, nActualItemsEmbedded);
+              AdjustCharPosInTextBlocks(pBuf, nActualItems, nActualItems + nActualItemsEmbedded - 1, I);
+              nActualItems += nActualItemsEmbedded;
               if (!pszEnd)
                 dwCookie |= COOKIE_BLOCK_SCRIPT;
               else
@@ -105,8 +114,11 @@ out:
           else if (dwCookie & COOKIE_BLOCK_STYLE)
             {
               const TCHAR *pszEnd = _tcsstr(pszChars + I, _T("</style>"));
-              int nextI = pszEnd ? (pszEnd - pszChars) : nLength;
-              dwCookie = ParseLineCss(dwCookie & ~COOKIE_BLOCK_STYLE, pszChars + I, nextI - I, pBuf, nActualItems);
+              int nextI = pszEnd ? static_cast<int>(pszEnd - pszChars) : nLength;
+              int nActualItemsEmbedded = 0;
+              dwCookie = ParseLineCss(dwCookie & ~COOKIE_BLOCK_STYLE, pszChars + I, nextI - I, pBuf + nActualItems, nActualItemsEmbedded);
+              AdjustCharPosInTextBlocks(pBuf, nActualItems, nActualItems + nActualItemsEmbedded - 1, I);
+              nActualItems += nActualItemsEmbedded;
               if (!pszEnd)
                 dwCookie |= COOKIE_BLOCK_STYLE;
               else
@@ -121,16 +133,18 @@ out:
               const TCHAR *pszEnd = _tcsstr(pszChars + I, _T("?>"));
               if (!pszEnd)
                 pszEnd = _tcsstr(pszChars + I, _T("%>"));
-              int nextI = pszEnd ? (pszEnd - pszChars) : nLength;
-              
+              int nextI = pszEnd ? static_cast<int>(pszEnd - pszChars) : nLength;
               unsigned (*pParseLineFunc)(unsigned, const TCHAR *, int, TEXTBLOCK *, int &);
               switch (nEmbeddedLanguage)
               {
               case SRC_BASIC: pParseLineFunc = ParseLineBasic; break;
               case SRC_PHP: pParseLineFunc = ParseLinePhpLanguage; break;
-              default: pParseLineFunc = ParseLineJava; break;
+              default: pParseLineFunc = ParseLineJavaScript; break;
               }
-              dwCookie = pParseLineFunc(dwCookie & ~COOKIE_EXT_USER1, pszChars + I, nextI - I, pBuf, nActualItems);
+              int nActualItemsEmbedded = 0;
+              dwCookie = pParseLineFunc(dwCookie & ~COOKIE_EXT_USER1, pszChars + I, nextI - I, pBuf + nActualItems, nActualItemsEmbedded);
+              AdjustCharPosInTextBlocks(pBuf, nActualItems, nActualItems + nActualItemsEmbedded - 1, I);
+              nActualItems += nActualItemsEmbedded;
               if (!pszEnd)
                 dwCookie |= COOKIE_EXT_USER1;
               else
@@ -231,9 +245,9 @@ out:
                   if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
                     {
                       DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
-                      if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<script"), sizeof(_T("<script") - 1)) == 0)
+                      if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<script"), sizeof("<script") - 1) == 0)
                         dwCookie |= COOKIE_BLOCK_SCRIPT;
-                      else if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<style"), sizeof(_T("<style") - 1)) == 0)
+                      else if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<style"), sizeof("<style") - 1) == 0)
                         dwCookie |= COOKIE_BLOCK_STYLE;
                     }
                   else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
@@ -316,9 +330,9 @@ next:
       if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
         {
           DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
-          if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<script"), sizeof(_T("<script") - 1)) == 0)
+          if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<script"), sizeof("<script") - 1) == 0)
             dwCookie |= COOKIE_BLOCK_SCRIPT;
-          else if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<style"), sizeof(_T("<style") - 1)) == 0)
+          else if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<style"), sizeof("<style") - 1) == 0)
             dwCookie |= COOKIE_BLOCK_STYLE;
         }
       else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
@@ -335,7 +349,7 @@ next:
         }
     }
 
-  dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_ELEMENT | COOKIE_EXT_USER1 | COOKIE_BLOCK_SCRIPT | COOKIE_BLOCK_STYLE);
+  dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_ELEMENT | COOKIE_EXT_USER1 | COOKIE_BLOCK_SCRIPT | COOKIE_BLOCK_STYLE | COOKIE_EXT_DEFINITION | COOKIE_EXT_VALUE);
   return dwCookie;
 }