【优化】优化type的属性解析,可以正确去掉多余括号
parent
41fd0a908b
commit
fa971c0e06
|
|
@ -339,7 +339,7 @@ namespace Luban.Job.Cfg.Defs
|
|||
case "path":
|
||||
case "range":
|
||||
{
|
||||
cf.Type = cf.Type + "&" + attrs[i];
|
||||
cf.Type = cf.Type + "&(" + attrs[i] + ")";
|
||||
break;
|
||||
}
|
||||
case "group":
|
||||
|
|
@ -665,16 +665,17 @@ namespace Luban.Job.Cfg.Defs
|
|||
{
|
||||
ValidAttrKeys(defineFile, e, _fieldOptionalAttrs, _fieldRequireAttrs);
|
||||
|
||||
string refStr = XmlUtil.GetOptionalAttribute(e, "ref");
|
||||
string typeStr = XmlUtil.GetRequiredAttribute(e, "type");
|
||||
|
||||
string refStr = XmlUtil.GetOptionalAttribute(e, "ref");
|
||||
if (!string.IsNullOrWhiteSpace(refStr))
|
||||
{
|
||||
typeStr = typeStr + "&ref=" + refStr;
|
||||
typeStr = typeStr + "&(ref=" + refStr + ")";
|
||||
}
|
||||
string pathStr = XmlUtil.GetOptionalAttribute(e, "path");
|
||||
if (!string.IsNullOrWhiteSpace(pathStr))
|
||||
{
|
||||
typeStr = typeStr + "&path=" + pathStr;
|
||||
typeStr = typeStr + "&(path=" + pathStr + ")";
|
||||
}
|
||||
|
||||
return CreateField(defineFile, XmlUtil.GetRequiredAttribute(e, "name"),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using Luban.Job.Cfg.Datas;
|
|||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
|
@ -163,7 +164,7 @@ namespace Luban.Job.Cfg.Validators
|
|||
public PathValidator(TType type, string pathPattern)
|
||||
{
|
||||
Type = type;
|
||||
this.RawPattern = pathPattern;
|
||||
this.RawPattern = DefUtil.TrimBracePairs(pathPattern);
|
||||
}
|
||||
|
||||
public void Validate(ValidatorContext ctx, TType type, DType data)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using Luban.Job.Cfg.Datas;
|
||||
using Luban.Job.Cfg.DataVisitors;
|
||||
using Luban.Job.Cfg.Defs;
|
||||
using Luban.Job.Cfg.Utils;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -31,7 +33,7 @@ namespace Luban.Job.Cfg.Validators
|
|||
public RefValidator(TType type, string tablesStr)
|
||||
{
|
||||
Type = type;
|
||||
this.Tables = new List<string>(tablesStr.Split(','));
|
||||
this.Tables = new List<string>(DefUtil.TrimBracePairs(tablesStr).Split(','));
|
||||
}
|
||||
|
||||
public void Validate(ValidatorContext ctx, TType type, DType key)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using Luban.Job.Cfg.Datas;
|
||||
using Luban.Job.Common.Defs;
|
||||
using Luban.Job.Common.Types;
|
||||
using Luban.Job.Common.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
|
@ -23,7 +24,7 @@ namespace Luban.Job.Cfg.Validators
|
|||
{
|
||||
_type = ttype;
|
||||
_datas = new HashSet<DType>();
|
||||
_valueSetStr = param;
|
||||
_valueSetStr = DefUtil.TrimBracePairs(param);
|
||||
}
|
||||
|
||||
public void Compile(DefFieldBase def)
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
public TType CreateType(string module, string type)
|
||||
{
|
||||
int sepIndex = DefUtil.IndexOfIncludeBrace(type, ',');
|
||||
int sepIndex = DefUtil.IndexOfElementTypeSep(type);
|
||||
if (sepIndex > 0)
|
||||
{
|
||||
string containerTypeAndTags = DefUtil.TrimBracePairs(type.Substring(0, sepIndex));
|
||||
|
|
@ -232,7 +232,7 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
protected TMap CreateMapType(string module, Dictionary<string, string> tags, string keyValueType, bool isTreeMap)
|
||||
{
|
||||
int typeSepIndex = DefUtil.IndexOfIncludeBrace(keyValueType, ',');
|
||||
int typeSepIndex = DefUtil.IndexOfElementTypeSep(keyValueType);
|
||||
if (typeSepIndex <= 0 || typeSepIndex >= keyValueType.Length - 1)
|
||||
{
|
||||
throw new ArgumentException($"invalid map element type:'{keyValueType}'");
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ namespace Luban.Job.Common.Utils
|
|||
return am;
|
||||
}
|
||||
|
||||
public static int IndexOfIncludeBrace(string s, char sep)
|
||||
public static int IndexOfElementTypeSep(string s)
|
||||
{
|
||||
int braceDepth = 0;
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
|
|
@ -54,7 +54,7 @@ namespace Luban.Job.Common.Utils
|
|||
--braceDepth;
|
||||
}
|
||||
|
||||
if (braceDepth == 0 && (c == sep))
|
||||
if (braceDepth == 0 && (c == ',' || c == ';'))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue