diff options
author | wolfbeast <mcwerewolf@gmail.com> | 2018-07-18 08:24:24 +0200 |
---|---|---|
committer | wolfbeast <mcwerewolf@gmail.com> | 2018-07-18 08:24:24 +0200 |
commit | fc61780b35af913801d72086456f493f63197da6 (patch) | |
tree | f85891288a7bd988da9f0f15ae64e5c63f00d493 /application/basilisk/components/translation/cld2/cldapp.cc | |
parent | 69f7f9e5f1475891ce11cc4f431692f965b0cd30 (diff) | |
parent | 50d3e596bbe89c95615f96eb71f6bc5be737a1db (diff) | |
download | UXP-fc61780b35af913801d72086456f493f63197da6.tar UXP-fc61780b35af913801d72086456f493f63197da6.tar.gz UXP-fc61780b35af913801d72086456f493f63197da6.tar.lz UXP-fc61780b35af913801d72086456f493f63197da6.tar.xz UXP-fc61780b35af913801d72086456f493f63197da6.zip |
Merge commit '50d3e596bbe89c95615f96eb71f6bc5be737a1db' into Basilisk-releasev2018.07.18
# Conflicts:
# browser/app/profile/firefox.js
# browser/components/preferences/jar.mn
Diffstat (limited to 'application/basilisk/components/translation/cld2/cldapp.cc')
-rw-r--r-- | application/basilisk/components/translation/cld2/cldapp.cc | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/application/basilisk/components/translation/cld2/cldapp.cc b/application/basilisk/components/translation/cld2/cldapp.cc new file mode 100644 index 000000000..4750cc54b --- /dev/null +++ b/application/basilisk/components/translation/cld2/cldapp.cc @@ -0,0 +1,107 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "public/compact_lang_det.h" + +#define MAX_RESULTS 3 + +class Language { +public: + Language(CLD2::Language lang) : mLang(lang) {} + + const char* getLanguageCode() const + { + return CLD2::LanguageCode(mLang); + } + +private: + const CLD2::Language mLang; +}; + +class LanguageGuess : public Language { +public: + LanguageGuess(CLD2::Language lang, char percent) : + Language(lang), mPercent(percent) {} + + char getPercent() const + { + return mPercent; + } + +private: + const char mPercent; +}; + + +class LanguageInfo : public Language { +public: + static LanguageInfo* detectLanguage(const char* buffer, bool isPlainText) + { + CLD2::Language languages[MAX_RESULTS] = {}; + int percentages[MAX_RESULTS] = {}; + bool isReliable = false; + + // This is ignored. + int textBytes; + + CLD2::Language bestGuess = DetectLanguageSummary( + buffer, strlen(buffer), isPlainText, + languages, percentages, &textBytes, + &isReliable); + + return new LanguageInfo(isReliable, bestGuess, languages, percentages); + } + + static LanguageInfo* detectLanguage(const char* buffer, bool isPlainText, + const char* tldHint, int encodingHint, + const char* languageHint) + { + CLD2::CLDHints hints = {languageHint, tldHint, encodingHint, CLD2::UNKNOWN_LANGUAGE}; + + CLD2::Language languages[MAX_RESULTS] = {}; + int percentages[MAX_RESULTS] = {}; + bool isReliable = false; + + // These are ignored. + double scores[MAX_RESULTS]; + int textBytes; + + CLD2::Language bestGuess = ExtDetectLanguageSummary( + buffer, strlen(buffer), isPlainText, + &hints, 0, + languages, percentages, scores, + nullptr, &textBytes, &isReliable); + + return new LanguageInfo(isReliable, bestGuess, languages, percentages); + } + + ~LanguageInfo() + { + for (int i = 0; i < MAX_RESULTS; i++) { + delete languages[i]; + } + } + + bool getIsReliable() const + { + return mIsReliable; + } + + const LanguageGuess* languages[MAX_RESULTS]; + +private: + LanguageInfo(bool isReliable, CLD2::Language bestGuess, + CLD2::Language languageIDs[MAX_RESULTS], + int percentages[MAX_RESULTS]) : + Language(bestGuess), mIsReliable(isReliable) + { + for (int i = 0; i < MAX_RESULTS; i++) { + languages[i] = new LanguageGuess(languageIDs[i], percentages[i]); + } + } + + const bool mIsReliable; +}; + +#include "cld.cpp" |