[前][次][番号順一覧][スレッド一覧]

ruby-changes:56370

From: Nobuyoshi <ko1@a...>
Date: Thu, 4 Jul 2019 18:59:09 +0900 (JST)
Subject: [ruby-changes:56370] Nobuyoshi Nakada: 12e06d32f5 (master): Use lstrip instead of gsub which can match only once

https://git.ruby-lang.org/ruby.git/commit/?id=12e06d32f5

From 12e06d32f55dff7f35c66842e5d6901857132060 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Thu, 4 Jul 2019 18:49:42 +0900
Subject: Use lstrip instead of gsub which can match only once


diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 7607779..5c10d7f 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -123,7 +123,7 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L123
 
       no += 1
 
-      line = line.chomp.gsub(/^\s*/, '')
+      line = line.chomp.lstrip
       if line[0, 1] == '$'
         handle_directive(line[1..-1], file, no)
         next
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index bc795b8..62965d0 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -800,11 +800,11 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L800
       md = new_lines[@line_index].match(/\A */)
       prev_indent = md[0].count(' ')
       if @check_new_auto_indent
-        @buffer_of_lines[@line_index] = ' ' * new_indent + @buffer_of_lines[@line_index].gsub(/\A */, '')
+        @buffer_of_lines[@line_index] = ' ' * new_indent + @buffer_of_lines[@line_index].lstrip
         @cursor = new_indent
         @byte_pointer = new_indent
       else
-        @line = ' ' * new_indent + @line.gsub(/\A */, '')
+        @line = ' ' * new_indent + @line.lstrip
         @cursor += new_indent - prev_indent
         @byte_pointer += new_indent - prev_indent
       end
@@ -1893,7 +1893,7 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1893
     if @is_multiline and @buffer_of_lines.size > @line_index + 1
       @cursor = calculate_width(@line)
       @byte_pointer = @line.bytesize
-      @line += ' ' + @buffer_of_lines.delete_at(@line_index + 1).gsub(/\A +/, '')
+      @line += ' ' + @buffer_of_lines.delete_at(@line_index + 1).lstrip
       @cursor_max = calculate_width(@line)
       @buffer_of_lines[@line_index] = @line
       @rerender_all = true
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]