diff options
| author | Xu Cheng | 2016-08-18 14:35:39 +0800 |
|---|---|---|
| committer | Xu Cheng | 2016-08-18 14:35:39 +0800 |
| commit | e423617d771b934da4c82ab30683d0a05aa20b45 (patch) | |
| tree | 363d215cf0ec4153b1bd93b303df4f7d0778a678 /Library/Homebrew/utils.rb | |
| parent | af3ad3cb86faf73b3c9f089fa496a0e01f43b9f0 (diff) | |
| download | brew-e423617d771b934da4c82ab30683d0a05aa20b45.tar.bz2 | |
remove ruby 1.8 compatible codes
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 90469bca9..0a1b5158d 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -561,11 +561,6 @@ def number_readable(number) numstr end -# True if this version of Ruby supports text encodings in its strings -def ruby_has_encoding? - String.method_defined?(:force_encoding) -end - # Truncates a text string to fit within a byte size constraint, # preserving character encoding validity. The returned string will # be not much longer than the specified max_bytes, though the exact @@ -579,13 +574,8 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {}) glue = "\n[...snip...]\n" max_bytes_in = [max_bytes - glue.bytesize, 1].max - if ruby_has_encoding? - bytes = s.dup.force_encoding("BINARY") - glue_bytes = glue.encode("BINARY") - else - bytes = s - glue_bytes = glue - end + bytes = s.dup.force_encoding("BINARY") + glue_bytes = glue.encode("BINARY") n_front_bytes = (max_bytes_in * front_weight).floor n_back_bytes = max_bytes_in - n_front_bytes if n_front_bytes == 0 @@ -599,10 +589,8 @@ def truncate_text_to_approximate_size(s, max_bytes, options = {}) back = bytes[-n_back_bytes..-1] end out = front + glue_bytes + back - if ruby_has_encoding? - out.force_encoding("UTF-8") - out.encode!("UTF-16", :invalid => :replace) - out.encode!("UTF-8") - end + out.force_encoding("UTF-8") + out.encode!("UTF-16", :invalid => :replace) + out.encode!("UTF-8") out end |
