未执行效果:
已执行效果:
未执行效果:
未执行效果:
代码:
public static StringList_ C_Preprocessor = new StringList_ { "include", "define","ifdef", "else", "elif", "endif", "ifndef", "line", "error", "pragma" };
/// <summary>
/// 记录C,C++代码中的预处理命令的位置
/// </summary>
/// <param name="sTrueText">注释用空格代替的文本</param>
/// <returns></returns>
/// 创建时间: 2022-10-01 最后一次修改时间:2022-10-01
public static DList_ <Pair_<int, int>> _Syntax_C_Find_Preprocessor(this string sTrueText)
{
DList_<Pair_<int, int>> dResult = new DList_<Pair_<int, int>>();
int j, k;
for (int i = 0; i < sTrueText.Length; i++)
{
char c1 = sTrueText[i];
//lg.D(c1.ToString(),"_Syntax_C_Find_Preprocessor");
//#ifndef _MS_WINDOWS_ 正确
//# ifndef _MS_WINDOWS_ 正确
//#include<test.h">
//# include <test.h> 正确
// # + 预处理命令 + ?
if (c1 == '#') //开始记录
{
j = i + 1;
while (j < sTrueText.Length)
{
char c2 = sTrueText[j];
if (c2._IsEnglishLetters())
{
StringBuilder sbWord = new StringBuilder(50);
sbWord.Append(c2);
//lg.D(c2.ToString(), "_Syntax_C_Find_Preprocessor");
k = j + 1;
while ( k < sTrueText.Length )
{
c2 = sTrueText[k];
if ( !c2._IsEnglishLetters() ) //遇到非英文字符停止
{
//lg.D(sbWord.ToString(), "_Syntax_C_Find_Preprocessor");
if ( Syntax_.C_Preprocessor.IndexOf(sbWord.ToString()) != -1) //判断是否预处理命令
{
dResult.Add(new Pair_<int, int>(i, k - i + 1));
}
j = k;
break;
}
else
{
sbWord.Append(c2);
}
++k;
}
i = j;
break;
}
++j;
}
}
}
return dResult;
}
public static StringList_ C_Preprocessor = new StringList_ { "include", "define","ifdef", "else", "elif", "endif", "ifndef", "line", "error", "pragma" };
/// <summary>
/// 记录C,C++代码中的预处理命令的位置
/// </summary>
/// <param name="sTrueText">注释用空格代替的文本</param>
/// <returns></returns>
/// 创建时间: 2022-10-01 最后一次修改时间:2022-10-01
public static DList_ <Pair_<int, int>> _Syntax_C_Find_Preprocessor(this string sTrueText)
{
DList_<Pair_<int, int>> dResult = new DList_<Pair_<int, int>>();
int j, k;
for (int i = 0; i < sTrueText.Length; i++)
{
char c1 = sTrueText[i];
//lg.D(c1.ToString(),"_Syntax_C_Find_Preprocessor");
//#ifndef _MS_WINDOWS_ 正确
//# ifndef _MS_WINDOWS_ 正确
//#include<test.h">
//# include <test.h> 正确
// # + 预处理命令 + ?
if (c1 == '#') //开始记录
{
j = i + 1;
while (j < sTrueText.Length)
{
char c2 = sTrueText[j];
if (c2._IsEnglishLetters())
{
StringBuilder sbWord = new StringBuilder(50);
sbWord.Append(c2);
//lg.D(c2.ToString(), "_Syntax_C_Find_Preprocessor");
k = j + 1;
while ( k < sTrueText.Length )
{
c2 = sTrueText[k];
if ( !c2._IsEnglishLetters() ) //遇到非英文字符停止
{
//lg.D(sbWord.ToString(), "_Syntax_C_Find_Preprocessor");
if ( Syntax_.C_Preprocessor.IndexOf(sbWord.ToString()) != -1) //判断是否预处理命令
{
dResult.Add(new Pair_<int, int>(i, k - i + 1));
}
j = k;
break;
}
else
{
sbWord.Append(c2);
}
++k;
}
i = j;
break;
}
++j;
}
}
}
return dResult;
}