mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-06 15:47:39 +03:00
Remove script method from hyphenator classes to streamline language-specific hyphenation logic
This commit is contained in:
parent
8822e83394
commit
34d2b81f40
@ -343,8 +343,6 @@ const EnglishHyphenator& EnglishHyphenator::instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
Script EnglishHyphenator::script() const { return Script::Latin; }
|
||||
|
||||
std::vector<size_t> EnglishHyphenator::breakIndexes(const std::vector<CodepointInfo>& cps) const {
|
||||
return englishBreakIndexes(cps);
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ class EnglishHyphenator final : public LanguageHyphenator {
|
||||
public:
|
||||
static const EnglishHyphenator& instance();
|
||||
|
||||
Script script() const override;
|
||||
std::vector<size_t> breakIndexes(const std::vector<CodepointInfo>& cps) const override;
|
||||
|
||||
private:
|
||||
|
||||
@ -9,8 +9,6 @@ struct CodepointInfo {
|
||||
size_t byteOffset;
|
||||
};
|
||||
|
||||
enum class Script { Latin, Cyrillic, Mixed };
|
||||
|
||||
// Minimum number of codepoints required in prefix and suffix for hyphenation.
|
||||
constexpr size_t MIN_PREFIX_CP = 2;
|
||||
constexpr size_t MIN_SUFFIX_CP = 2;
|
||||
|
||||
@ -13,25 +13,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
// Central registry for language-specific hyphenators supported on device.
|
||||
const std::array<const LanguageHyphenator*, 2>& registeredHyphenators() {
|
||||
static const std::array<const LanguageHyphenator*, 2> hyphenators = {
|
||||
&EnglishHyphenator::instance(),
|
||||
&RussianHyphenator::instance(),
|
||||
};
|
||||
return hyphenators;
|
||||
}
|
||||
|
||||
// Finds the hyphenator matching the detected script.
|
||||
const LanguageHyphenator* hyphenatorForScript(const Script script) {
|
||||
for (const auto* hyphenator : registeredHyphenators()) {
|
||||
if (hyphenator->script() == script) {
|
||||
return hyphenator;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Maps a BCP-47 language tag to a language-specific hyphenator.
|
||||
const LanguageHyphenator* hyphenatorForLanguage(const std::string& langTag) {
|
||||
if (langTag.empty()) return nullptr;
|
||||
@ -109,7 +90,6 @@ std::vector<size_t> collectBreakIndexes(const std::vector<CodepointInfo>& cps) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Use cached hyphenator to avoid repeated language lookups.
|
||||
if (const auto* hyphenator = cachedHyphenator()) {
|
||||
auto indexes = hyphenator->breakIndexes(cps);
|
||||
return indexes;
|
||||
|
||||
@ -7,6 +7,5 @@
|
||||
class LanguageHyphenator {
|
||||
public:
|
||||
virtual ~LanguageHyphenator() = default;
|
||||
virtual Script script() const = 0;
|
||||
virtual std::vector<size_t> breakIndexes(const std::vector<CodepointInfo>& cps) const = 0;
|
||||
};
|
||||
|
||||
@ -405,8 +405,6 @@ const RussianHyphenator& RussianHyphenator::instance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
Script RussianHyphenator::script() const { return Script::Cyrillic; }
|
||||
|
||||
std::vector<size_t> RussianHyphenator::breakIndexes(const std::vector<CodepointInfo>& cps) const {
|
||||
return russianBreakIndexes(cps);
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ class RussianHyphenator final : public LanguageHyphenator {
|
||||
public:
|
||||
static const RussianHyphenator& instance();
|
||||
|
||||
Script script() const override;
|
||||
std::vector<size_t> breakIndexes(const std::vector<CodepointInfo>& cps) const override;
|
||||
|
||||
private:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user