把 struct 和 class 一同处理
/// <summary>
/// 找出程序设计语言,Java,C#,C++中的自定义类
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
/// 创建时间: 2022-08-26 最后一次修改时间:2022-08-30
public static StringList_ _Syntax_C_FindCustomClass(this string sText)
{
String sTureText = _Syntax_C_Remove_ExplanatoryNote(sText); //第一,除去注释
StringList_ slResult = new StringList_();
String[] keyWordArray = { "class", "struct" }; //class 与 struct
foreach(string sKeyWord in keyWordArray )
{
int nPos = sTureText._IndexOfWord(sKeyWord, 0);
while (nPos != -1)
{
int n = sTureText.IndexOf("{", nPos + sKeyWord.Length);
//class node; 前置声明
int iSemicolonPos = sTureText.IndexOf(";",nPos + sKeyWord.Length);
if (n != -1 && iSemicolonPos > n) //除了前置声明,第一个分号一定在 { 后面
{
//class Point2d : public Point {
string sClass = sTureText.Substring(nPos + sKeyWord.Length, n - nPos - sKeyWord.Length);
if(sClass.IndexOf(":") != -1)
{
StringList_ slTemp = sClass._Split(":");
if(slTemp.Count > 1)
{
slResult.Add(slTemp[0].Trim());
slTemp = slTemp[1].Trim()._Split(" ", true);
if(slTemp.Count > 1)
{
slResult.Add(slTemp[1]); //父类
}
}
}
else //template < class type, int dim > class Point { } = type, int dim > class Point
{
if(sClass.IndexOf(',') != -1 || sClass.IndexOf('>') != -1) //模板 template < class T >
{ }
else
{
slResult.Add(sClass.Trim());
}
}
}
nPos = sTureText._IndexOfWord(sKeyWord, nPos + sKeyWord.Length);
}
}
return slResult;
}
/// <summary>
/// 找出程序设计语言,Java,C#,C++中的自定义类
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
/// 创建时间: 2022-08-26 最后一次修改时间:2022-08-30
public static StringList_ _Syntax_C_FindCustomClass(this string sText)
{
String sTureText = _Syntax_C_Remove_ExplanatoryNote(sText); //第一,除去注释
StringList_ slResult = new StringList_();
String[] keyWordArray = { "class", "struct" }; //class 与 struct
foreach(string sKeyWord in keyWordArray )
{
int nPos = sTureText._IndexOfWord(sKeyWord, 0);
while (nPos != -1)
{
int n = sTureText.IndexOf("{", nPos + sKeyWord.Length);
//class node; 前置声明
int iSemicolonPos = sTureText.IndexOf(";",nPos + sKeyWord.Length);
if (n != -1 && iSemicolonPos > n) //除了前置声明,第一个分号一定在 { 后面
{
//class Point2d : public Point {
string sClass = sTureText.Substring(nPos + sKeyWord.Length, n - nPos - sKeyWord.Length);
if(sClass.IndexOf(":") != -1)
{
StringList_ slTemp = sClass._Split(":");
if(slTemp.Count > 1)
{
slResult.Add(slTemp[0].Trim());
slTemp = slTemp[1].Trim()._Split(" ", true);
if(slTemp.Count > 1)
{
slResult.Add(slTemp[1]); //父类
}
}
}
else //template < class type, int dim > class Point { } = type, int dim > class Point
{
if(sClass.IndexOf(',') != -1 || sClass.IndexOf('>') != -1) //模板 template < class T >
{ }
else
{
slResult.Add(sClass.Trim());
}
}
}
nPos = sTureText._IndexOfWord(sKeyWord, nPos + sKeyWord.Length);
}
}
return slResult;
}