MCPcopy Create free account
hub / github.com/ProgerXP/Notepad2e / classifyTagHTML

Function classifyTagHTML

scintilla/lexers/LexHTML.cxx:261–318  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259}
260
261static int classifyTagHTML(unsigned int start, unsigned int end,
262 WordList &keywords, Accessor &styler, bool &tagDontFold,
263 bool caseSensitive, bool isXml, bool allowScripts) {
264 char withSpace[30 + 2] = " ";
265 const char *s = withSpace + 1;
266 // Copy after the '<'
267 unsigned int i = 1;
268 for (unsigned int cPos = start; cPos <= end && i < 30; cPos++) {
269 char ch = styler[cPos];
270 if ((ch != '<') && (ch != '/')) {
271 withSpace[i++] = caseSensitive ? ch : static_cast<char>(MakeLowerCase(ch));
272 }
273 }
274
275 //The following is only a quick hack, to see if this whole thing would work
276 //we first need the tagname with a trailing space...
277 withSpace[i] = ' ';
278 withSpace[i+1] = '\0';
279
280 // if the current language is XML, I can fold any tag
281 // if the current language is HTML, I don't want to fold certain tags (input, meta, etc.)
282 //...to find it in the list of no-container-tags
283 tagDontFold = (!isXml) && (NULL != strstr(" area base basefont br col command embed frame hr img input isindex keygen link meta param source track wbr ", withSpace));
284
285 //now we can remove the trailing space
286 withSpace[i] = '\0';
287
288 // No keywords -> all are known
289 char chAttr = SCE_H_TAGUNKNOWN;
290 if (s[0] == '!') {
291 chAttr = SCE_H_SGML_DEFAULT;
292 } else if (!keywords || keywords.InList(s)) {
293 chAttr = SCE_H_TAG;
294 }
295 styler.ColourTo(end, chAttr);
296 if (chAttr == SCE_H_TAG) {
297 if (allowScripts && 0 == strcmp(s, "script")) {
298 // check to see if this is a self-closing tag by sniffing ahead
299 bool isSelfClose = false;
300 for (unsigned int cPos = end; cPos <= end + 200; cPos++) {
301 char ch = styler.SafeGetCharAt(cPos, '\0');
302 if (ch == '\0' || ch == '>')
303 break;
304 else if (ch == '/' && styler.SafeGetCharAt(cPos + 1, '\0') == '>') {
305 isSelfClose = true;
306 break;
307 }
308 }
309
310 // do not enter a script state if the tag self-closed
311 if (!isSelfClose)
312 chAttr = SCE_H_SCRIPT;
313 } else if (!isXml && 0 == strcmp(s, "comment")) {
314 chAttr = SCE_H_COMMENT;
315 }
316 }
317 return chAttr;
318}

Callers 1

ColouriseHyperTextDocFunction · 0.85

Calls 4

InListMethod · 0.80
ColourToMethod · 0.80
SafeGetCharAtMethod · 0.80
MakeLowerCaseFunction · 0.50

Tested by

no test coverage detected