diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-28 09:43:26 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-07-28 09:47:40 +0900 |
commit | a6e32855d079e8f3806d8be8a5f5cf7b3a967133 (patch) | |
tree | 06cd13d11df6d635b8750388e2f5daf41ea21b14 /lib/reline | |
parent | bce348204f7f4105500397cacb709498e15d9857 (diff) | |
download | ruby-a6e32855d079e8f3806d8be8a5f5cf7b3a967133.tar.gz |
[reline] Do not escape and compile regexp for each byte
Diffstat (limited to 'lib/reline')
-rw-r--r-- | lib/reline/line_editor.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index e9e693eb2b..0de4234225 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -808,6 +808,8 @@ class Reline::LineEditor rest = nil break_pointer = nil quote = nil + closing_quote = nil + escaped_quote = nil i = 0 while i < @byte_pointer do slice = @line.byteslice(i, @byte_pointer - i) @@ -815,14 +817,16 @@ class Reline::LineEditor i += 1 next end - if quote and slice.start_with?(/(?!\\)#{Regexp.escape(quote)}/) # closing " + if quote and slice.start_with?(closing_quote) quote = nil i += 1 - elsif quote and slice.start_with?(/\\#{Regexp.escape(quote)}/) # escaped \" + elsif quote and slice.start_with?(escaped_quote) # skip i += 2 elsif slice =~ quote_characters_regexp # find new " - quote = $& + quote = $~ + closing_quote = /(?!\\)#{Regexp.escape(quote)}/ + escaped_quote = /\\#{Regexp.escape(quote)}/ i += 1 elsif not quote and slice =~ word_break_regexp rest = $' |