diff options
author | Eric Wong <e@80x24.org> | 2020-09-29 02:31:08 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2020-09-29 03:01:49 +0000 |
commit | 63b9c52697a579f53fefc476bcc630420de422ac (patch) | |
tree | 113bc85a252017f0e154225ea3f10ce099a8865e /lib/dtas/encoding.rb | |
parent | 0f248206429674778e1c6837a188438af362ef50 (diff) | |
download | dtas-63b9c52697a579f53fefc476bcc630420de422ac.tar.gz |
Ruby case/when is not like C with fall-through, so we can't rely on fall-through behavior to use CharlockHolmes to detect legacy encodings.
Diffstat (limited to 'lib/dtas/encoding.rb')
-rw-r--r-- | lib/dtas/encoding.rb | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/dtas/encoding.rb b/lib/dtas/encoding.rb index dad54af..bbc6076 100644 --- a/lib/dtas/encoding.rb +++ b/lib/dtas/encoding.rb @@ -11,15 +11,14 @@ module DTAS::Encoding # :nodoc: private def try_enc_harder(str, enc, old) # :nodoc: + begin + require 'charlock_holmes' + @charlock_holmes = CharlockHolmes::EncodingDetector.new + rescue LoadError + @charlock_holmes = false + end if @charlock_holmes.nil? + case @charlock_holmes - when nil - begin - require 'charlock_holmes' - @charlock_holmes = CharlockHolmes::EncodingDetector.new - rescue LoadError - warn "`charlock_holmes` gem not available for encoding detection" - @charlock_holmes = false - end when false enc_fallback(str, enc, old) else |