From: Eric Wong <e@80x24.org>
To: dtas-all@nongnu.org
Subject: [PATCH] encoding: use CharlockHolmes properly on first run
Date: Tue, 29 Sep 2020 02:31:08 +0000 [thread overview]
Message-ID: <20200929023108.8325-1-e@80x24.org> (raw)
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.
---
lib/dtas/encoding.rb | 15 +++++++--------
1 file 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 @@ def self.extended(mod)
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
reply other threads:[~2020-09-29 2:31 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://80x24.org/dtas/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200929023108.8325-1-e@80x24.org \
--to=e@80x24.org \
--cc=dtas-all@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/dtas.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).