Skip to content

Commit

Permalink
enhance string
Browse files Browse the repository at this point in the history
  • Loading branch information
changlie committed Oct 16, 2022
1 parent 5090922 commit d13eb65
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion core/097function_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var DEFAULT_STR_VALUE string
var JSON_ARRAY_TYPE = reflect.TypeOf(emptyArray())
var JSON_OBJECT_TYPE = reflect.TypeOf(emptyJsonObject())
var BYTE_ARRAY_TYPE = reflect.TypeOf(EMPTY_BYTE_ARRAY)
var STR_ARRAY_TYPE = reflect.TypeOf(DEFAULT_STR_VALUE)
var STR_ARRAY_TYPE = reflect.TypeOf(EMPTY_STR_ARRAY)
var BOOL_TYPE = reflect.TypeOf(DEFAULT_BOOL_VALUE)
var INT_TYPE = reflect.TypeOf(DEFAULT_INT_VALUE)
var I32_TYPE = reflect.TypeOf(DEFAULT_I32_VALUE)
Expand Down
17 changes: 15 additions & 2 deletions core/101value_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,21 @@ func (this *StringValue) Clear(target string) string {
func (this *StringValue) Contains(subStr string) bool {
return strings.Contains(this.goValue, subStr)
}
func (this *StringValue) Has(subStr string) bool {
return strings.Contains(this.goValue, subStr)
func (this *StringValue) Has(subStrs []string) bool {
for _, subStr := range subStrs {
if strings.Contains(this.goValue, subStr) {
return true
}
}
return false
}
func (this *StringValue) With(subStrs []string) bool {
for _, subStr := range subStrs {
if !strings.Contains(this.goValue, subStr) {
return false
}
}
return true
}
func (this *StringValue) Lower() string {
return strings.ToLower(this.goValue)
Expand Down
10 changes: 10 additions & 0 deletions examples/type_str_check.qk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

echo(`$ abc$`)


"abc post fast hello world: loop".has("tt", "AJ", "lo").pr()

echo("string with method!")
echo("------------------------------------------")
"abc post fast hello world: loop".with("tt", "AJ", "lo").pr()
"abc post fast hello world: loop".with("fa", "ab", "lo").pr()
2 changes: 1 addition & 1 deletion test/single_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func Test_demo(t *testing.T) {
// errorLog(err)
// }
// }()
demo, _ := filepath.Abs("../examples/type_str_templ.qk")
demo, _ := filepath.Abs("../examples/type_str_check.qk")
//demo, _ := filepath.Abs("../examples/demo.qk")
// core.DEBUG = true
core.TestFlag = true
Expand Down

0 comments on commit d13eb65

Please sign in to comment.