0.3 版
0.4 版
/// <summary>
/// 找出程序设计语言,Java,C#,C++中的自定义类
/// </summary>
/// <param name="sText"></param>
/// <returns></returns>
/// 创建时间: 2022-08-26 最后一次修改时间:2022-09-26
public static UStringListCI_ _Syntax_C_FindCustomClass(this string sText)
{
String sTureText = _Syntax_C_Remove_ExplanatoryNote(sText); //第一,除去注释
UStringListCI_ slResult = new UStringListCI_();
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());
//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 { };
//slTemp[1] = "public virtual X"
//slTemp[1] = "public virtual X"
//slTemp[1] = "public A, public B "
//slTemp[1] = "public C "
String sParent = slTemp[1].Trim();
//除去关键字
sParent = sParent.Replace("public", "");
sParent = sParent.Replace("private", "");
sParent = sParent.Replace("virtual", "").Trim();
slTemp = sParent._Split(",", true); //多重继承
slResult.Add(slTemp);
}
}
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;
}