From 7c867121e32d52f2b8cd6d02f3d9316e6e842e6d Mon Sep 17 00:00:00 2001 From: gentee Date: Thu, 12 Nov 2020 09:02:55 +0500 Subject: [PATCH] Added Length to Set Variable --- script/embedded.go | 2 +- script/gentee.go | 16 ---------------- script/varobj.go | 8 ++++++++ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/script/embedded.go b/script/embedded.go index 9c720a7..0c661a5 100644 --- a/script/embedded.go +++ b/script/embedded.go @@ -120,6 +120,7 @@ var ( {Prototype: `Condition(str,str) bool`, Object: Condition}, {Prototype: `File(str) str`, Object: FileLoad}, {Prototype: `Form(str)`, Object: Form}, + {Prototype: `IsObjVar(str) bool`, Object: IsVarObj}, {Prototype: `IsVar(str) bool`, Object: IsVar}, {Prototype: `LogOutput(int,str)`, Object: LogOutput}, {Prototype: `Macro(str) str`, Object: Macro}, @@ -137,7 +138,6 @@ var ( {Prototype: `GetVarObj(str) obj`, Object: GetVarObj}, // For gentee {Prototype: `YamlToMap(str) map`, Object: YamlToMap}, - {Prototype: `FindFirstRegExp(str,str) arr.str`, Object: FindFirstRegExpºStrStr}, } ) diff --git a/script/gentee.go b/script/gentee.go index 43d5f33..9dbd6d5 100644 --- a/script/gentee.go +++ b/script/gentee.go @@ -5,8 +5,6 @@ package script import ( - "regexp" - "github.com/gentee/gentee" "github.com/gentee/gentee/core" "gopkg.in/yaml.v2" @@ -27,17 +25,3 @@ func YamlToMap(in string) (*core.Map, error) { } return ret.(*core.Map), nil } - -// FindFirstRegExpºStrStr returns an array of the first successive matches of the expression -func FindFirstRegExpºStrStr(src, rePattern string) (*core.Array, error) { - re, err := regexp.Compile(rePattern) - if err != nil { - return nil, err - } - list := re.FindStringSubmatch(src) - out := core.NewArray() - for _, sub := range list { - out.Data = append(out.Data, sub) - } - return out, nil -} diff --git a/script/varobj.go b/script/varobj.go index 4d84ade..040da9d 100644 --- a/script/varobj.go +++ b/script/varobj.go @@ -111,6 +111,14 @@ func GetVarObj(name string) (*core.Obj, error) { return val.(*core.Obj), nil } +func IsVarObj(name string) int64 { + _, ok := dataScript.ObjVars[len(dataScript.ObjVars)-1].Load(name) + if ok { + return 1 + } + return 0 +} + func setRawVarObj(shift int, name string, value *core.Obj) error { off := len(dataScript.ObjVars) - 1 - shift if off < 0 {