gitlab.com/evatix-go/core@v1.3.55/coreinstruction/StringSearch.go (about) 1 package coreinstruction 2 3 import ( 4 "gitlab.com/evatix-go/core/corecomparator" 5 "gitlab.com/evatix-go/core/enums/stringcompareas" 6 "gitlab.com/evatix-go/core/regexnew" 7 ) 8 9 type StringSearch struct { 10 corecomparator.BaseIsIgnoreCase 11 CompareMethod stringcompareas.Variant 12 Search string 13 } 14 15 func (it *StringSearch) IsEmpty() bool { 16 return it == nil 17 } 18 19 func (it *StringSearch) IsExist() bool { 20 return it != nil 21 } 22 23 func (it *StringSearch) Has() bool { 24 return it != nil 25 } 26 27 func (it *StringSearch) IsMatch(content string) bool { 28 if it == nil { 29 return true 30 } 31 32 return it.CompareMethod.IsCompareSuccess( 33 it.IsIgnoreCase, 34 content, 35 it.Search, 36 ) 37 } 38 39 func (it *StringSearch) IsAllMatch(contents ...string) bool { 40 if len(contents) == 0 { 41 return true 42 } 43 44 for _, content := range contents { 45 if it.IsMatchFailed(content) { 46 return false 47 } 48 } 49 50 return true 51 } 52 53 func (it *StringSearch) IsAnyMatchFailed(contents ...string) bool { 54 return !it.IsAllMatch(contents...) 55 } 56 57 func (it *StringSearch) IsMatchFailed(content string) bool { 58 return !it.IsMatch(content) 59 } 60 61 func (it *StringSearch) VerifyError(content string) error { 62 if it == nil { 63 return nil 64 } 65 66 if it.CompareMethod.IsRegex() { 67 return regexnew.MatchErrorLock( 68 it.Search, 69 content) 70 } 71 72 return it.CompareMethod.VerifyError( 73 it.IsIgnoreCase, 74 content, 75 it.Search, 76 ) 77 }