aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPhil Crosby2015-09-20 23:41:36 -0700
committerPhil Crosby2015-09-20 23:41:36 -0700
commitb2a194a58def7a3b1084a6f338bb48d6edd9397b (patch)
treeca4f517e1ce4fe8cc64d3066bfcbbb41e98408f8 /lib
parent34452f22ec4c6403deecb59b73d237bcfa7c964a (diff)
parent011a6b01fd2d05b5e3fa0181d6b5477e105616ca (diff)
downloadvimium-b2a194a58def7a3b1084a6f338bb48d6edd9397b.tar.bz2
Merge pull request #1086 from mrmr1993/countMatches
Rework to make match counting code for searches more DRY and easier to read
Diffstat (limited to 'lib')
-rw-r--r--lib/utils.coffee6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/utils.coffee b/lib/utils.coffee
index 350b11a5..b69b926b 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -19,6 +19,12 @@ Utils =
func = obj[components.pop()]
func.apply(obj, argArray)
+ # Escape all special characters, so RegExp will parse the string 'as is'.
+ # Taken from http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
+ escapeRegexSpecialCharacters: do ->
+ escapeRegex = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g
+ (str) -> str.replace escapeRegex, "\\$&"
+
escapeHtml: (string) -> string.replace(/</g, "&lt;").replace(/>/g, "&gt;")
# Generates a unique ID