Skip to content

Commit

Permalink
Merge pull request #1823 from koenpunt/abstracted-regex
Browse files Browse the repository at this point in the history
Abstracted get_search_regex for future testing
  • Loading branch information
stof committed Mar 12, 2014
2 parents 9f381e5 + 29261ca commit 0cd779d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions coffee/lib/abstract-chosen.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ class AbstractChosen

searchText = this.get_search_text()
escapedSearchText = searchText.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")
regexAnchor = if @search_contains then "" else "^"
regex = new RegExp(regexAnchor + escapedSearchText, 'i')
zregex = new RegExp(escapedSearchText, 'i')
regex = this.get_search_regex(escapedSearchText)

for option in @results_data

Expand Down Expand Up @@ -177,6 +176,10 @@ class AbstractChosen
this.update_results_content this.results_option_build()
this.winnow_results_set_highlight()

get_search_regex: (escaped_search_string) ->
regex_anchor = if @search_contains then "" else "^"
new RegExp(regex_anchor + escaped_search_string, 'i')

search_string_match: (search_string, regex) ->
if regex.test search_string
return true
Expand Down

0 comments on commit 0cd779d

Please # to comment.