1 ///////////////////////////////////////////////////////////////////////////
4 // Updated: 02-Dec-2006
6 // Copyright: Ferdinand Prantl, portions by Stcherbatchenko Andrei,
7 // Tim Gerundt, Kimmo Varis
8 // E-mail: prantl@ff.cuni.cz
10 // INI syntax highlighing definition
12 // You are free to use or modify this code to the following restrictions:
13 // - Acknowledge me somewhere in your about box, simple "Parts of code by.."
14 // will be enough. If you can't (or don't want to), contact me personally.
15 // - LEAVE THIS HEADER INTACT
16 ////////////////////////////////////////////////////////////////////////////
19 #include "crystallineparser.h"
20 #include "../SyntaxColors.h"
21 #include "../utils/string_util.h"
28 CrystalLineParser::ParseLineIni (DWORD dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
31 return dwCookie & COOKIE_EXT_COMMENT;
33 bool bFirstChar = (dwCookie & ~COOKIE_EXT_COMMENT) == 0;
34 bool bRedefineBlock = true;
35 bool bDecIndex = false;
39 for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars))
43 // CharNext did not advance, so we're at the end of the string
44 // and we already handled this character, so stop
53 if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
55 DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
57 else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
59 DEFINE_BLOCK (nPos, COLORINDEX_STRING);
61 else if (dwCookie & COOKIE_SECTION)
63 DEFINE_BLOCK (nPos, COLORINDEX_FUNCNAME);
65 else if (dwCookie & COOKIE_KEY)
67 DEFINE_BLOCK (nPos, COLORINDEX_KEYWORD);
71 if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.' && nPos > 0 && (!xisalpha (*::CharPrev(pszChars, pszChars + nPos)) && !xisalpha (*::CharNext(pszChars + nPos))))
73 DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
77 DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR);
78 bRedefineBlock = true;
83 bRedefineBlock = false;
88 // Can be bigger than length if there is binary data
89 // See bug #1474782 Crash when comparing SQL with with binary data
90 if (I >= nLength || pszChars[I] == 0)
93 if (dwCookie & COOKIE_COMMENT)
95 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
96 dwCookie |= COOKIE_COMMENT;
100 // String constant "...."
101 if (dwCookie & COOKIE_STRING)
103 if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
105 dwCookie &= ~COOKIE_STRING;
106 bRedefineBlock = true;
111 // Char constant '..'
112 if (dwCookie & COOKIE_CHAR)
114 if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
116 dwCookie &= ~COOKIE_CHAR;
117 bRedefineBlock = true;
122 // Section header [...]
123 if (dwCookie & COOKIE_SECTION)
125 if (pszChars[I] == ']')
127 dwCookie &= ~COOKIE_SECTION;
128 bRedefineBlock = true;
134 if (dwCookie & COOKIE_KEY)
136 if (I + 1 < nLength && pszChars[I + 1] == '=')
138 dwCookie &= ~COOKIE_KEY;
139 bRedefineBlock = true;
145 if (pszChars[I] == '"')
147 DEFINE_BLOCK (I, COLORINDEX_STRING);
148 dwCookie |= COOKIE_STRING;
151 if (pszChars[I] == '\'')
153 // 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] == '\'')
154 if (!I || !xisalnum (pszChars[nPrevI]))
156 DEFINE_BLOCK (I, COLORINDEX_STRING);
157 dwCookie |= COOKIE_CHAR;
164 if (pszChars[I] == ';') // Comment
166 DEFINE_BLOCK (I, COLORINDEX_COMMENT);
167 dwCookie |= COOKIE_COMMENT;
170 else if (pszChars[I] == '[') // Section header [...]
172 DEFINE_BLOCK (I, COLORINDEX_FUNCNAME);
173 dwCookie |= COOKIE_SECTION;
178 DEFINE_BLOCK (I, COLORINDEX_KEYWORD);
179 dwCookie |= COOKIE_KEY;
181 if (!xisspace (pszChars[I]))
186 continue; // We don't need to extract keywords,
187 // for faster parsing skip the rest of loop
189 if (xisalnum (pszChars[I]) || pszChars[I] == '.' && I > 0 && (!xisalpha (pszChars[nPrevI]) && !xisalpha (pszChars[I + 1])))
191 if (nIdentBegin == -1)
196 if (nIdentBegin >= 0)
198 if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
200 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
202 bRedefineBlock = true;
209 if (nIdentBegin >= 0)
211 if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
213 DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
217 dwCookie &= COOKIE_EXT_COMMENT;