mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Use a simpler escapeRegExp method
This commit is contained in:
@@ -26,40 +26,7 @@ _.mixin
|
||||
original.apply(this, args)
|
||||
|
||||
escapeRegExp: (string) ->
|
||||
# Referring to the table here:
|
||||
# https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/regexp
|
||||
# these characters should be escaped
|
||||
# \ ^ $ * + ? . ( ) | { } [ ]
|
||||
# These characters only have special meaning inside of brackets
|
||||
# they do not need to be escaped, but they MAY be escaped
|
||||
# without any adverse effects (to the best of my knowledge and casual testing)
|
||||
# : ! , =
|
||||
# my test "~!@#$%^&*(){}[]`/=?+\|-_;:'\",<.>".match(/[\#]/g)
|
||||
|
||||
specials = [
|
||||
# order matters for these
|
||||
"-"
|
||||
"["
|
||||
"]"
|
||||
# order doesn't matter for any of these
|
||||
"/"
|
||||
"{"
|
||||
"}"
|
||||
"("
|
||||
")"
|
||||
"*"
|
||||
"+"
|
||||
"?"
|
||||
"."
|
||||
"\\"
|
||||
"^"
|
||||
"$"
|
||||
"|"]
|
||||
|
||||
# I choose to escape every character with '\'
|
||||
# even though only some strictly require it when inside of []
|
||||
regex = RegExp('[' + specials.join('\\') + ']', 'g')
|
||||
string.replace(regex, "\\$&")
|
||||
string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
|
||||
|
||||
humanizeEventName: (eventName, eventDoc) ->
|
||||
[namespace, event] = eventName.split(':')
|
||||
|
||||
Reference in New Issue
Block a user