fix: 修复TrimBracePairs方法可能会出现的问题
parent
02f3ebd979
commit
bfc13bc35f
|
|
@ -275,7 +275,7 @@ namespace Luban.Job.Common.Defs
|
||||||
|
|
||||||
public TType CreateType(string module, string type)
|
public TType CreateType(string module, string type)
|
||||||
{
|
{
|
||||||
type = DefUtil.TrimBracePairs(type, true);
|
type = DefUtil.TrimBracePairs(type);
|
||||||
int sepIndex = DefUtil.IndexOfBaseTypeEnd(type);
|
int sepIndex = DefUtil.IndexOfBaseTypeEnd(type);
|
||||||
if (sepIndex > 0)
|
if (sepIndex > 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,45 @@ namespace Luban.Job.Common.Utils
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string TrimBracePairs(string rawType, bool soft = false)
|
public static string TrimBracePairs(string rawType)
|
||||||
|
{
|
||||||
|
while (rawType.Length > 0 && rawType[0] == '(')
|
||||||
|
{
|
||||||
|
int braceDepth = 0;
|
||||||
|
int level1Left = -1;
|
||||||
|
int level1Right = -1;
|
||||||
|
for (int i = 0; i < rawType.Length; i++)
|
||||||
|
{
|
||||||
|
if (rawType[i] == '(')
|
||||||
|
{
|
||||||
|
braceDepth++;
|
||||||
|
if (level1Left < 0)
|
||||||
|
{
|
||||||
|
level1Left = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rawType[i] == ')')
|
||||||
|
{
|
||||||
|
braceDepth--;
|
||||||
|
if (level1Right < 0 && braceDepth == 0)
|
||||||
|
{
|
||||||
|
level1Right = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (level1Left >= 0 && level1Right == rawType.Length - 1)
|
||||||
|
{
|
||||||
|
rawType = rawType.Substring(1, rawType.Length - 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rawType;
|
||||||
|
}
|
||||||
|
public static string TrimBracePairs2(string rawType, bool soft = false)
|
||||||
{
|
{
|
||||||
while (rawType.Length > 0 && rawType[0] == '(')
|
while (rawType.Length > 0 && rawType[0] == '(')
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue