From bfc13bc35f3cae57fc8020c8a13e788c3f73a328 Mon Sep 17 00:00:00 2001 From: Carson Lin <396098651@qq.com> Date: Wed, 13 Jul 2022 12:50:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DTrimBracePairs?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=8F=AF=E8=83=BD=E4=BC=9A=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/Defs/DefAssemblyBase.cs | 2 +- src/Luban.Job.Common/Source/Utils/DefUtil.cs | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs index 64e33d5..8c72367 100644 --- a/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs +++ b/src/Luban.Job.Common/Source/Defs/DefAssemblyBase.cs @@ -275,7 +275,7 @@ namespace Luban.Job.Common.Defs public TType CreateType(string module, string type) { - type = DefUtil.TrimBracePairs(type, true); + type = DefUtil.TrimBracePairs(type); int sepIndex = DefUtil.IndexOfBaseTypeEnd(type); if (sepIndex > 0) { diff --git a/src/Luban.Job.Common/Source/Utils/DefUtil.cs b/src/Luban.Job.Common/Source/Utils/DefUtil.cs index b17069a..3ba7024 100644 --- a/src/Luban.Job.Common/Source/Utils/DefUtil.cs +++ b/src/Luban.Job.Common/Source/Utils/DefUtil.cs @@ -136,7 +136,45 @@ namespace Luban.Job.Common.Utils 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] == '(') {