From 3806f1883a15d24b249b03ced3d5039ed2168d26 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Fri, 26 Dec 2025 04:42:58 +0500 Subject: [PATCH] Refactor breakOffsets function: simplify return statements and improve readability --- lib/Epub/Epub/hyphenation/Hyphenator.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/Epub/Epub/hyphenation/Hyphenator.cpp b/lib/Epub/Epub/hyphenation/Hyphenator.cpp index 888de0c..cecdc38 100644 --- a/lib/Epub/Epub/hyphenation/Hyphenator.cpp +++ b/lib/Epub/Epub/hyphenation/Hyphenator.cpp @@ -88,25 +88,17 @@ size_t byteOffsetForIndex(const std::vector& cps, const size_t in } // namespace std::vector Hyphenator::breakOffsets(const std::string& word, const bool includeFallback) { - std::vector byteOffsets; if (word.empty()) { - return byteOffsets; + return {}; } auto cps = collectCodepoints(word); trimTrailingPunctuation(cps); if (cps.size() < MIN_PREFIX_CP + MIN_SUFFIX_CP) { - return byteOffsets; - } - - std::vector indexes; - indexes.reserve(cps.size()); - - if (hasOnlyAlphabetic(cps)) { - auto dictBreaks = collectBreakIndexes(cps); - indexes.insert(indexes.end(), dictBreaks.begin(), dictBreaks.end()); + return {}; } + std::vector indexes = hasOnlyAlphabetic(cps) ? collectBreakIndexes(cps) : std::vector(); if (includeFallback) { for (size_t idx = MIN_PREFIX_CP; idx + MIN_SUFFIX_CP <= cps.size(); ++idx) { indexes.push_back(idx); @@ -114,16 +106,16 @@ std::vector Hyphenator::breakOffsets(const std::string& word, const bool } if (indexes.empty()) { - return byteOffsets; + return {}; } std::sort(indexes.begin(), indexes.end()); indexes.erase(std::unique(indexes.begin(), indexes.end()), indexes.end()); + std::vector byteOffsets; byteOffsets.reserve(indexes.size()); for (const size_t idx : indexes) { byteOffsets.push_back(byteOffsetForIndex(cps, idx)); } - return byteOffsets; }