例子:
在RichTextBox中:
System::Void RichTextBoxForm::tsmi_PythonColor_Click(System::Object^ sender, System::EventArgs^ e)
{
_Syntax sy(m_rtbEx->SelectedText);
_SyntaxData sd;
auto kcList = sy.GetTextColorPos_Python(sd);
m_rtbEx->IsLockPaint = true;
int nOldSelectionStart = m_rtbEx->SelectionStart;
int nOldSelectionLength = m_rtbEx->SelectionLength;
for (_TextColor tc : kcList)
{
m_rtbEx->SelectionStart = nOldSelectionStart + tc.Pos;
m_rtbEx->SelectionLength = tc.Length;
m_rtbEx->SelectionColor = tc.ForeColor;
//m_rtbEx.SelectionFont = new Font(m_rtbEx.HeadlineStyle.MainBody, FontStyle.Bold);
if (tc.IsBold)
{
m_rtbEx->SelectionFont = gcnew Drawing::Font(m_rtbEx->SelectionFont, FontStyle::Bold);
}
}
m_rtbEx->SelectionStart = nOldSelectionStart;
m_rtbEx->SelectionLength = nOldSelectionLength;
m_rtbEx->IsLockPaint = false;
}
下面函数记录要着色的Python关键字位置及其颜色
/// <summary>
/// 记录要着色的Python关键字位置及其颜色。
/// </summary>
/// <param name="sData"></param>
/// <returns></returns>
/// 创建时间: 2022-04-17 最后一次修改时间:2022-05-02
_DList<_TextColor> _Syntax::GetTextColorPos_Python(_SyntaxData& sd)
{
sd.ClearMemory(); //清空原来的数据
_DList<_TextColor> dtResult;
//可见字符开始位置
const _char* p = _code.Data;
//可见字符长度
const int iTextLength = _code.Length;
if (iTextLength <= 0) return dtResult;
_string sWord(_t(""), 50); //50个_char缓冲
_Color cKeyWordColor = GetColor(_SyntaxType::关键字);
_Color cExplanatoryNode = GetColor(_SyntaxType::注释);
_Color cOS = GetColor(_SyntaxType::运算符号);
for (int i = 0; i < iTextLength; ++i)
{
if (p[i] == _t('#')) //----------------------------------------------注释
{
int nEnd = i + 1;
while (p[nEnd] && p[nEnd] != _t('\n'))
{
++nEnd;
}
dtResult.Add(_TextColor(i, nEnd - i, cExplanatoryNode));
i = nEnd;
}
else if (p[i] == _t('\"'))
{
//三引号注释 查找后面两个字符是否也是 \"\" 双引号,如果是,则是注释
int j = i + 1;
int nCount1 = 1;
bool bExplanatoryNote = true;
while (j < iTextLength)
{
if (p[j] == _t('\"'))
{
++nCount1;
if (nCount1 == 3) //是三个双引号注译
{
//这里查找下一个三双引号注译,遍历文本直到结尾,直到找到为止。
int k = j + 1;
int nCount2 = 0;
while (k < iTextLength)
{
if (p[k] == _t('\"'))
{
++nCount2;
if (nCount2 == 3) //注释结束
{
dtResult.Add(_TextColor(i, k + 1 - i, cExplanatoryNode));
i = k + 1;
break;
}
}
else if (p[k] == _t(' ')) { }
else
{
nCount2 = 0;
}
++k;
}
break;
}
}
else if (p[j] == _t(' '))
{
}
else
{
bExplanatoryNote = false;
break;
}
++j;
}
if (!bExplanatoryNote) //不是注释
{
//字符串开始
if (i - 1 > 0 && p[i - 1] != _t('\\'))
{
int iStart = i;
++i;
bool bFind = false; //查找下一个 "\""
while (i < iTextLength)
{
if (p[i] == '\"' && p[i - 1] != _t('\\'))
{
bFind = true;
break;
}
else if (p[i] == _t('\n')) //当前行已结束,还未找到引号配对
{
bFind = true;
break;
}
++i;
}
if (!bFind)
{
return dtResult;
}
else
{
dtResult.Add(_TextColor(iStart, i - iStart + 1, _Color::字符串));
}
}
else
{
++i;
}
}
}
else if (p[i] == _t('\''))
{
//三单引号注释 查找后面两个字符是否也是 \"\" 双引号,如果是,则是注释
int j = i + 1;
int nCount1 = 1;
bool bExplanatoryNote = true;
while (j < iTextLength)
{
if (p[j] == _t('\''))
{
++nCount1;
if (nCount1 == 3) //是三个双引号注译
{
//这里查找下一个三双引号注译,遍历文本直到结尾,直到找到为止。
int k = j + 1;
int nCount2 = 0;
while (k < iTextLength)
{
if (p[k] == _t('\''))
{
++nCount2;
if (nCount2 == 3) //注释结束
{
dtResult.Add(_TextColor(i, k + 1 - i, cExplanatoryNode));
i = k + 1;
break;
}
}
else if (p[k] == _t(' ')) {}
else
{
nCount2 = 0;
}
++k;
}
break;
}
}
else if (p[j] == _t(' '))
{
}
else
{
bExplanatoryNote = false;
break;
}
++j;
}
if (!bExplanatoryNote) //不是注释
{
if (i - 1 > 0 && p[i - 1] != _t('\\'))
{
int iStart = i;
++i;
bool bFind = false; //查找下一个 "\'"
while (i < iTextLength)
{
if (p[i] == _t('\'') && p[i - 1] != _t('\\'))
{
bFind = true;
break;
}
else if (p[i] == _t('\n')) //当前行已结束,还未找到引号配对
{
bFind = true;
break;
}
++i;
}
if (!bFind)
{
return dtResult;
}
else
{
dtResult.Add(_TextColor(iStart, i - iStart + 1, _Color::字符串));
}
}
else
{
++i;
}
}
}
else if (p[i] == _t('{')) //大括号查找全部文本
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength; ++j) //查找配对,直到文本结尾
{
_char cRight = p[j];
if (cRight == _t('}'))
{
if (iFlag == 0)
{
//_Color c = gca::color_RandomColor();
_Color c = _Color::Red;
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('{'))
{
++iFlag;
}
}
}
else if (p[i] == _t('['))
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength; ++j) //查找配对,直到遇到换行符号停止;
{
_char cRight = p[j];
if (cRight == _t(']'))
{
if (iFlag == 0)
{
//_Color c = gca::color_RandomColor();
_Color c = _Color::Red;
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('['))
{
++iFlag;
}
else if (cRight == _t('\n') ) //遇到换行符号停止
{
break;
}
}
}
else if (p[i] == _t('('))
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength; ++j) //查找配对,直到遇到分号;
{
_char cRight = p[j];
if (cRight == _t(')'))
{
if (iFlag == 0)
{
//_Color c = gca::color_RandomColor();
_Color c = _Color::Red;
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('('))
{
++iFlag;
}
else if (cRight == _t(';'))
{
break;
}
}
//这里找出是否函数定义
int j = i - 1;
//去掉空格
while (j > 0)
{
if (p[j] != _t(' ')) { break; }
--j;
}
_string sFun(_t(""), 50);
while (j > 0)
{
if (!gs.s_Syntax_IsWordSeparator(p[j]))
{
sFun.Add(p[j]);
}
else
{
break;
}
--j;
}
if (sFun.Length > 0)
{
sFun.Reversal();
if (Python_Keyword.IndexOf(sFun) == -1) //不是关键字
{
dtResult.Add(_TextColor(j + 1, sFun.Length, _Color::函数));
//log::d(sFun);
}
}
}
else if (C_OperationalCharacter.IndexOf(p[i]) != -1) //运算符或者标点符号
{
dtResult.Add(_TextColor(i, 1, _Color::Red));
}
//开始查找,关键字,自定义类、等等
if (gs.s_Syntax_IsWordSeparator(p[i]))
{
if (sWord.Length > 0)
{
bool bFind = false;
//自定义类
_DListNode<_SyntaxClass>* pClass = sd.Class.First();
while (pClass != null)
{
if (pClass->Data.Name == sWord)
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, _Color::自定义类));
//log::d(pClass->Data.Name);
bFind = true;
break;
}
pClass = pClass->Next;
}
//自定义函数
_DListNode<_SyntaxFunction>* pFun = sd.Function.First();
while (pFun != null)
{
if (pFun->Data.Name == sWord)
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, _Color::自定义函数));
bFind = true;
break;
}
pFun = pFun->Next;
}
if (!bFind) //自定义类和函数不能是关键字
{
//关键字最小长度大于2,且全是小写字母
if (sWord.Length >= 2)
{
int n = sd.DefineClass.IndexOf(sWord);
if (sWord == _t("class") || sWord == _t("struct") || n != -1) //分析类定义,如果不在 #define 定义中
{
//这里判断Python类的名字
}
else
{
if (Python_Keyword.IndexOf(sWord) != -1) //是关键字,记录位置
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, cKeyWordColor));
}
else
{
//log::d(sWord);
}
}
}
}
//log::d(_getc(sWord));
sWord.Clear(); //清空
}
}
else
{
sWord.Add(p[i]);
}
}
return dtResult;
}
_StringList _Syntax::Python_Keyword =
{
//blue
_t("True"),
_t("False"),
_t("await"),
_t("else"),
_t("import"),
_t("pass"),
_t("None"),
_t("break"),
_t("except"),
_t("in"),
_t("raise"),
_t("and"),
_t("or"),
_t("finally"),
_t("is"),
_t("return"),
_t("as"),
_t("for"),
_t("lambda"),
_t("try"),
//red
_t("assert"),
_t("def"),
_t("from"),
_t("nonlocal"),
_t("while"),
_t("async"),
_t("del"),
_t("global"),
_t("not"),
_t("with"),
//yellow
_t("class"),
_t("if"),
_t("yield"),
//green
_t("continue"),
_t("exec"),
_t("print"),
_t("imp"),
_t("pkgutil"),
_t("ctypes") /* 更多关键字可以自行添加 */
};
这个函数有不完善的地方,因为是刚刚从C++着色中拿来的,测试不多,以下是C++着色部分,C++着色前面已有例子,C++要复杂得多,注意:Python注释与C++注释最大的不同。
以下是着色C++着色:
/// <summary>
/// 一次性记录关键字,注释,字符串值,运算符,宏,括号配对,预处理命令的位置,并设置自定义数据颜色
/// 2023-03-05 修改 {[( 的颜色从随机颜色改为非随机颜色,如果不改,每次重新着色时颜色会改变。
/// </summary>
/// <param name="CustomData">生成自定义数据列表</param>
/// <returns></returns>
/// 创建时间: 2022-12-24 最后一次修改时间:2023-03-05
_DList<_TextColor> _Syntax::GetTextColorPos_C(_SyntaxData &sd)
{
sd.ClearMemory(); //清空原来的数据
_DList<_TextColor> dtResult;
//可见字符开始位置
const _char* p = _code.Data;
//可见字符长度
const int iTextLength = _code.Length;
if (iTextLength <= 0) return dtResult;
_string sWord(_t(""), 50); //50个_char缓冲
_Color cKeyWordColor = GetColor(_SyntaxType::关键字);
_Color cExplanatoryNode = GetColor(_SyntaxType::注释);
_Color cOS = GetColor(_SyntaxType::运算符号);
for (int i = 0; i < iTextLength; ++i)
{
if (p[i] == _t('/'))
{
++i;
if (i < iTextLength)
{
if (p[i] == _t('/')) //是"//"注释,查找注释结束位置 \n ,跳过注释
{
int iStart = i - 1;
++i;
bool bFind = false; //查找下一个 "\n"
while (i < iTextLength)
{
if (p[i] == '\n')
{
bFind = true;
break;
}
++i;
}
if (!bFind)
{
return dtResult;
}
else
{
dtResult.Add(_TextColor(iStart, i - iStart, cExplanatoryNode));
}
}
else if (p[i] == _t('*')) //是"/*"注释,查找注释结束位置 */ ,跳过注释
{
int iStart = i - 1;
++i;
bool bFind = false;
while (i + 1 < iTextLength ) //查找下一个 "*/"
{
if (p[i] == '*' && p[i + 1] == '/')
{
i += 1;
bFind = true;
break;
}
++i;
}
if (!bFind)
{
return dtResult;
}
else
{
dtResult.Add(_TextColor(iStart, i - iStart + 1, cExplanatoryNode));
}
}
}
else
{
return dtResult;
}
}
else if (p[i] == _t('\"')) { //字符串开始
if (i - 1 > 0 && p[i - 1] != _t('\\'))
{
int iStart = i;
++i;
bool bFind = false; //查找下一个 "\""
while (i < iTextLength )
{
if (p[i] == '\"' && p[i - 1] != _t('\\'))
{
bFind = true;
break;
}
else if (p[i] == _t('\n')) //当前行已结束,还未找到引号配对
{
bFind = true;
break;
}
++i;
}
if (!bFind)
{
return dtResult;
}
else
{
dtResult.Add(_TextColor(iStart, i - iStart + 1, _Color::字符串));
}
}
else
{
++i;
}
}
else if (p[i] == _t('\'')) { //字符开始
if (i - 1 > 0 && p[i - 1] != _t('\\'))
{
int iStart = i;
++i;
bool bFind = false; //查找下一个 "\'"
while (i < iTextLength )
{
if (p[i] == _t('\'') && p[i - 1] != _t('\\'))
{
bFind = true;
break;
}
else if (p[i] == _t('\n')) //当前行已结束,还未找到引号配对
{
bFind = true;
break;
}
++i;
}
if (!bFind)
{
return dtResult;
}
else
{
dtResult.Add(_TextColor(iStart, i - iStart + 1, _Color::字符串));
}
}
else
{
++i;
}
}
else if (_Syntax::C_OperationalCharacter.IndexOf(p[i]) != -1)
{
dtResult.Add(_TextColor(i, 1, cOS));
}
else if (p[i] == _t('{')) //大括号查找全部文本
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength ; ++j) //查找配对,直到遇到分号;
{
_char cRight = p[j];
if (cRight == _t('}'))
{
if (iFlag == 0)
{
//_Color c = _Color::RedRandom();
_Color c = _Color::Red;
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('{'))
{
++iFlag;
}
}
}
else if ( p[i] == _t('['))
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength; ++j) //查找配对,直到遇到分号;
{
_char cRight = p[j];
if (cRight == _t(']'))
{
if (iFlag == 0)
{
_Color c = _Color::Red; //_Color::RedRandom();
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('['))
{
++iFlag;
}
else if (ga.c_IsPunctuation(cRight)) //遇到标点符号停止
{
break;
}
}
}
else if (p[i] == _t('('))
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength; ++j) //查找配对,直到遇到分号;
{
_char cRight = p[j];
if (cRight == _t(')'))
{
if (iFlag == 0)
{
_Color c = _Color::Red; //_Color::RedRandom();
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('('))
{
++iFlag;
}
else if (cRight == _t(';'))
{
break;
}
}
//这里找出是否函数定义
int j = i - 1;
//去掉空格
while (j > 0)
{
if (p[j] != _t(' ')) { break; }
--j;
}
_string sFun(_t(""), 50);
while (j > 0)
{
if (!gs.s_Syntax_IsWordSeparator(p[j]))
{
sFun.Add(p[j]);
}
else
{
break;
}
--j;
}
if (sFun.Length > 0)
{
sFun.Reversal();
if (C_Keyword.IndexOf(sFun) == -1) //不是关键字
{
dtResult.Add(_TextColor(j + 1, sFun.Length, _Color::函数));
//log::d(sFun);
}
}
}
else if (p[i] == _t('<')) //这里究竟是小于号还是尖括号
{
int iFlag = 0;
for (int j = i + 1; j < iTextLength; ++j) //查找配对,直到遇到分号;
{
_char cRight = p[j];
if (cRight == _t('>'))
{
if (iFlag == 0)
{
_Color c = _Color::Red; //_Color::RedRandom();
dtResult.Add(_TextColor(i, 1, c));
dtResult.Add(_TextColor(j, 1, c));
break;
}
--iFlag;
}
else if (cRight == _t('<'))
{
++iFlag;
}
else if (cRight == _t(';'))
{
break;
}
}
}
else if (p[i] == _t('#'))
{ //这里开始分析C++宏定义语法
//#ifndef _MS_WINDOWS_ 正确
//# ifndef _MS_WINDOWS_ 正确
//#include<test.h">
//# include <test.h> 正确
// # + 预处理命令 + ?
//着色预处理命令
_string s1(_t(""), 50), s2(_t(""), 50), s3(_t(""), 50);
int j = i + 1;
int k = j;
//跳过空格
while (j < iTextLength) { if (p[j] == _t(' ')) ++j; else break; }
while (j < iTextLength){
if (!gs.s_Syntax_IsWordSeparator(p[j])){
s1.Add(p[j]);
}else{
break;
}
++j;
}
if (C_Preprocessor.IndexOf(s1) != -1){ dtResult.Add(_TextColor(i, j - i, _Color::Red)); }
if (s1 == _t("define"))
{
//#define _pi(var) (_cout <<#var<<_t(" = ")<<_tostr(var) << _t("\t"))
//#define _class class
//语法一:
//#define 标识符 被标识符代表的字符串 //这种用法很简单,就是一种替换.
//语法二 :
//#define 标识符[(参数1,.....,参数n)] 被标识符代表的字符串 //其中,在"被标识符代表的字符串"中出现的形参将在使用时被实参替代. 就像写函数一样.
// 补充一点 : 在用#define 定义时, 可以用斜杠("\") 续行.与vb中的下划线(" _")作用同.
//检查有没有续行符
bool bContinuation = false;
//检查最后一位字符是不是续行符
k = j;
while (k < iTextLength)
{
if (p[k] == _t('\n'))
{
break;
}
++k;
}
//宏定义续行
if (p[k - 1] == '\\') { bContinuation = true; }
//跳过空格
while (j < iTextLength) { if (p[j] == _t(' ')) ++j; else break; }
//拷贝第一部分
while (j < iTextLength) {
if (p[j] != _t(' ')) {
s2.Add(p[j]);
}
else {
break;
}
++j;
}
if (s2.IndexOf(_t('(')) != -1) //函数格式
{
//跳过空格
while (j < iTextLength) { if (p[j] == _t(' ')) ++j; else break; }
if (bContinuation)
{
//拷贝第二部分
++k;
while (k < iTextLength && bContinuation)
{
if (p[k] == _t('\n'))
{
if (p[k - 1] != _t('\\'))
{
bContinuation = false;
break;
}
}
if (!bContinuation)break;
++k;
}
for (int m = j; m < k; ++m)
{
if (p[m] != _t('\n') && p[m] != _t('\\'))
s3.Add(p[m]);
}
}
else
{
//拷贝第二部分,拷贝到行尾
while (j < iTextLength) {
if (p[j] != _t('\n'))
{
s3.Add(p[j]);
}
else
{
break;
}
++j;
}
}
}
else
{
//跳过空格
while (j < iTextLength) { if (p[j] == _t(' ')) ++j; else break; }
if (bContinuation)
{
//拷贝第二部分
++k;
while (k < iTextLength && bContinuation)
{
if (p[k] == _t('\n'))
{
if (p[k - 1] != _t('\\'))
{
bContinuation = false;
break;
}
}
if (!bContinuation)break;
++k;
}
for (int m = j; m < k; ++m)
{
if(p[m] != _t('\n') && p[m] != _t('\\'))
s3.Add(p[m]);
}
}
else
{
//拷贝第二部分
while (j < iTextLength) {
if (p[j] != _t(' ') && p[j] != _t('\n'))
{
s3.Add(p[j]);
}
else
{
break;
}
++j;
}
}
sd.Define.Add(_Pair<_string, _string>(s2, s3));
//#define _class class
if (s3 == _t("class") || s3 == _t("struct"))
{
sd.DefineClass.Add(s2);
}
}
//log::d(s2);
//log::d(s3);
}
//i = k; //把 字符定位在#define 最后
i = i + s1.Length;
}
//开始查找,关键字,自定义类、等等
if (gs.s_Syntax_IsWordSeparator(p[i]))
{
if (sWord.Length > 0)
{
bool bFind = false;
//自定义类
_DListNode<_SyntaxClass>* pClass = sd.Class.First();
while (pClass != null)
{
if (pClass->Data.Name == sWord)
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, _Color::自定义类));
//log::d(pClass->Data.Name);
bFind = true;
break;
}
pClass = pClass->Next;
}
//自定义函数
_DListNode<_SyntaxFunction> *pFun = sd.Function.First();
while (pFun != null)
{
if (pFun->Data.Name == sWord)
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, _Color::自定义函数));
bFind = true;
break;
}
pFun = pFun->Next;
}
if(!bFind) //自定义类和函数不能是关键字
{
//关键字最小长度大于2,且全是小写字母
if (sWord.Length >= 2)
{
int n = sd.DefineClass.IndexOf(sWord);
if ( sWord == _t("class") || sWord == _t("struct") || n != -1 ) //分析类定义,如果不在 #define 定义中
{
//template<class T> T Max(T t1, T t2) { }
// template<class T1, class T2> v
//class X { public : int i; };
//class A : public virtual X { public : int j ; };
//class B : public virtual X { public : double d; } ;
//class C : public A, public B { public : int k; };
//class D : public C { };
//class _Str : public _Str<A>{};
//class
//bb{ };
//class CC : public std::string{}
//class cc{};
//template<class T> class Int{}; //先出现 >
//typedef class MyClass* pMyClass;
//#define _class class
//#define _class
//
//class
//
//_class dd{};
//
if (n == -1)
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, cKeyWordColor));
}
else
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, _Color::宏定义值));
}
bool bDef = false;
//一定要 j = i - 1,否则可能跳到下一行内
//例:
//#define _string class
//
//...
for (int j = i - 1; j > 0; --j)
{
if (p[j] == _t('#'))
{
bDef = true;
break;
}
if (p[j] == _t('\n')) break;
}
if (!bDef) //如果不是在宏义中
{
bool bFind = false;
int j = i + 1;
int iCopyStart = -1;
int bCopyEnd = false;
_string sClassName(_t(""), 50);
while (j < iTextLength)
{
//if (p[j] == _t(';')) break; //typedef class MyClass* pMyClass;
//比{ 和 : 先出现的 > 和 , 都是模板参数 或者 typedef
if (p[j] == '>' || p[j] == _t(',') || p[j] == _t(';'))
{
break;
}
if (p[j] == _t('{') || p[j] == _t(':'))
{
bFind = true;
break;
}
if (p[j] != _t(' ') && p[j] != _t('\t') && p[j] != _t('\n'))
{
if (iCopyStart == -1) iCopyStart = j; //拷贝开始
if (!bCopyEnd) sClassName.Add(p[j]);
}
else
{
if (iCopyStart != -1) bCopyEnd = true; //拷贝结束,因为遇到了空格或 \t 或 \n
}
++j;
}
if (bFind && iCopyStart != -1)
{
_SyntaxClass s;
s.Name = sClassName;
s.DefinitionPos = i + 1;
dtResult.Add(_TextColor(iCopyStart, sClassName.Length, _Color::自定义类));
sd.Class.Add(s); //添加自定义类
i = j;
}
}
}
else
{
if (C_Keyword.IndexOf(sWord) != -1) //是关键字,记录位置
{
dtResult.Add(_TextColor(i - sWord.Length, sWord.Length, cKeyWordColor));
}
else
{
//log::d(sWord);
}
}
}
}
//log::d(_getc(sWord));
sWord.Clear(); //清空
}
}
else
{
sWord.Add(p[i]);
}
}
return dtResult;
}