summaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
authorParsa Ghadimi <me@qti3e.com>2018-05-30 17:03:55 +0430
committerRyan Dahl <ry@tinyclouds.org>2018-05-30 08:33:55 -0400
commit2242c6c7921fcb681d3be7683fba862b4954b04a (patch)
tree12a1b50c1e180caafb35a7f37df64aed98e8399d /util.go
parent1156467c937f5b9af532a25fa80a706eea8f959d (diff)
Use wildcard to check stack trace outputs (#3)
Diffstat (limited to 'util.go')
-rw-r--r--util.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/util.go b/util.go
index 2662a256b..d5b83c393 100644
--- a/util.go
+++ b/util.go
@@ -6,6 +6,7 @@ import (
"fmt"
"net/url"
"os"
+ "strings"
)
func logDebug(format string, v ...interface{}) {
@@ -59,3 +60,47 @@ func async(cb func()) {
wg.Done()
}()
}
+
+const wildcard = "[WILDCARD]"
+
+// Matches the pattern string against the text string. The pattern can
+// contain "[WILDCARD]" substrings which will match one or more characters.
+// Returns true if matched.
+func patternMatch(pattern string, text string) bool {
+ // Empty pattern only match empty text.
+ if len(pattern) == 0 {
+ return len(text) == 0
+ }
+
+ if pattern == wildcard {
+ return true
+ }
+
+ parts := strings.Split(pattern, wildcard)
+
+ if len(parts) == 1 {
+ return pattern == text
+ }
+
+ if strings.HasPrefix(text, parts[0]) {
+ text = text[len(parts[0]):]
+ } else {
+ return false
+ }
+
+ for i := 1; i < len(parts); i++ {
+ // If the last part is empty, we match.
+ if i == len(parts)-1 {
+ if parts[i] == "" || parts[i] == "\n" {
+ return true
+ }
+ }
+ index := strings.Index(text, parts[i])
+ if index < 0 {
+ return false
+ }
+ text = text[index+len(parts[i]):]
+ }
+
+ return len(text) == 0
+}