📄 htmlcodestate.cpp
字号:
/***************************************************************************/
/* NOTE: */
/* This document is copyright (c) by Oz Solomon and Yonat Sharon, and is */
/* bound by the MIT open source license. */
/* See License.txt or visit www.opensource.org/licenses/mit-license.html */
/***************************************************************************/
#include "CodeState.h"
const CodeState* HTMLCodeState()
{
// states
enum {
cString, // outside any tags
cEntity, // after reading "&"
cInTag, // after reading "<"
cNormal, // inside a tag
cBegComment1, // after reading "<!"
cBegComment2, // after reading "<!-"
cBlockComment, // after reading "<!--"
cEndComment2, // after reading "-"
cEndComment1, // after reading "--"
cStatesNum
};
static CodeState states[cStatesNum];
static bool initialized = false;
if (initialized)
return &states[0];
#ifndef NDEBUG
states[cNormal].itsName = "Normal";
states[cString].itsName = "String";
states[cEntity].itsName = "Entity";
states[cInTag].itsName = "InTag";
states[cBegComment1].itsName = "BegComment1";
states[cBegComment2].itsName = "BegComment2";
states[cEndComment2].itsName = "EndComment2";
states[cEndComment1].itsName = "EndComment1";
#endif // NDEBUG
CodeEffect e;
//
// "do nothing" effects
//
e.markPosition = false;
e.action = 0;
// getting inside a tag
e.next = &states[cNormal];
states[cInTag][CodeParser::cDefaultDatum] = e;
states[cBegComment1][CodeParser::cDefaultDatum] = e;
states[cBegComment2][CodeParser::cDefaultDatum] = e;
// not getting out of a comment
e.next = &states[cBlockComment];
states[cEndComment1][CodeParser::cDefaultDatum] = e;
states[cEndComment2][CodeParser::cDefaultDatum] = e;
// other "do nothing"s
e.next = &states[cBegComment2];
states[cBegComment1]['-'] = e;
e.next = &states[cEndComment2];
states[cBlockComment]['-'] = e;
//
// effects that just mark position
//
e.markPosition = true;
e.next = &states[cBegComment1];
states[cInTag]['!'] = e;
e.next = &states[cEndComment1];
states[cEndComment2]['-'] = e;
e.next = 0;
states[cString][CodeParser::cDefaultDatum] = e;
//
// effects with actions
//
// getting out of tags/entities
e.markPosition = true;
e.next = &states[cString];
e.action = CodeParser::Context::BegString;
states[cNormal]['>'] = e;
states[cEntity][';'] = e;
states[cInTag]['>'] = e;
states[cBegComment1]['>'] = e;
states[cBegComment2]['>'] = e;
e.markPosition = false; // for all other effects
// begin comment
e.next = &states[cBlockComment];
e.action = CodeParser::Context::BegBlockComment;
states[cBegComment2]['-'] = e;
// start tag
e.next = &states[cInTag];
e.action = CodeParser::Context::EndString;
states[cString]['<'] = e;
// start entity
e.next = &states[cEntity];
states[cString]['&'] = e;
// end comment
e.next = &states[cString];
e.action = CodeParser::Context::BegString; // TODO: also EndBlockComment
states[cEndComment1]['>'] = e;
initialized = true;
return &states[0];
}
#ifdef TEST_HTML_CODE_STATE
#include "TestContext.h"
char str[] =
"<Title>map<Key, Data, Compare, Alloc></Title>\n"
"<!-- Generated by htmldoc -->\n"
"</HEAD>\n"
"<BODY BGCOLOR=\"#ffffff\" LINK=\"#0000ee\" TEXT=\"#000000\" VLINK=\"#551a8b\" \n"
" ALINK=\"#ff0000\"> \n"
"<IMG SRC=\"CorpID.gif\" \n"
" ALT=\"Silicon Graphics, Inc.\" HEIGHT=\"43\" WIDTH=\"151\"> \n"
"<!--end header-->\n"
"<BR Clear>\n"
"<tt>Map</tt> has the important property that inserting a new element\n"
"into a <tt>set</tt> does not invalidate iterators that point to existing\n"
"elements. Erasing an element from a set also does not invalidate\n"
"any iteratores, except, of course, for iterators that actually point \n"
"to the element that is being erased.\n"
"<h3>Example</h3>\n";
int main()
{
TestContext t(str);
CodeParser cp(HTMLCodeState(), &t);
cp.Process(str, sizeof(str));
return 0;
}
#endif // TEST_HTML_CODE_STATE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -