From 6d46fd15299657860ebaedf856494de0fdfdc756 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Fri, 7 Dec 2018 16:18:49 +0300 Subject: [PATCH] Zim, Aard: Fix language recognition from three-letter codes --- aard.cc | 4 ++-- langcoder.cc | 12 ------------ langcoder.hh | 2 -- zim.cc | 2 +- 4 files changed, 3 insertions(+), 17 deletions(-) diff --git a/aard.cc b/aard.cc index 579880a0..6d5a2871 100644 --- a/aard.cc +++ b/aard.cc @@ -1061,12 +1061,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idxHeader.wordCount = wordCount; if( langFrom.size() == 3) - idxHeader.langFrom = LangCoder::code3toInt( langFrom.c_str() ); + idxHeader.langFrom = LangCoder::findIdForLanguageCode3( langFrom.c_str() ); else if( langFrom.size() == 2 ) idxHeader.langFrom = LangCoder::code2toInt( langFrom.c_str() ); if( langTo.size() == 3) - idxHeader.langTo = LangCoder::code3toInt( langTo.c_str() ); + idxHeader.langTo = LangCoder::findIdForLanguageCode3( langTo.c_str() ); else if( langTo.size() == 2 ) idxHeader.langTo = LangCoder::code2toInt( langTo.c_str() ); diff --git a/langcoder.cc b/langcoder.cc index 29f3b044..6d90f47a 100644 --- a/langcoder.cc +++ b/langcoder.cc @@ -266,18 +266,6 @@ QString LangCoder::intToCode2( quint32 val ) return QString::fromLatin1( code, 2 ); } -quint32 LangCoder::code3toInt(const std::string& code3) -{ - if (code3.length() < 2) - return 0; - - // this is temporary - char code1 = tolower( code3.at(1) ); - char code0 = tolower( code3.at(0) ); - - return ( ((quint32)code1) << 8 ) + (quint32)code0; -} - quint32 LangCoder::findIdForLanguage( gd::wstring const & lang ) { gd::wstring langFolded = Folding::apply( lang ); diff --git a/langcoder.hh b/langcoder.hh index e2e7cbf1..565f89cc 100644 --- a/langcoder.hh +++ b/langcoder.hh @@ -35,8 +35,6 @@ public: static QString intToCode2( quint32 ); - static quint32 code3toInt(const std::string& code3); - /// Finds the id for the given language name, written in english. The search /// is case- and punctuation insensitive. static quint32 findIdForLanguage( gd::wstring const & ); diff --git a/zim.cc b/zim.cc index c1e2a98a..e1e3c8e1 100644 --- a/zim.cc +++ b/zim.cc @@ -1674,7 +1674,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( idxHeader.langFrom = LangCoder::code2toInt( lang.c_str() ); else if( lang.size() == 3 ) - idxHeader.langFrom = LangCoder::code3toInt( lang.c_str() ); + idxHeader.langFrom = LangCoder::findIdForLanguageCode3( lang.c_str() ); idxHeader.langTo = idxHeader.langFrom; } }