[core] nits

Signed-off-by: x7z4w <x7z4w@noreply.codeberg.org>
This commit is contained in:
x7z4w
2025-08-21 13:56:48 +00:00
committed by Konstantin Pastbin
parent 3f7815017e
commit 3c34765595
5 changed files with 19 additions and 11 deletions

View File

@@ -8,7 +8,6 @@
#include <cmath>
#include <cstddef>
#include <iomanip>
#include <iterator>
#include <fast_double_parser.h>
#include <boost/algorithm/string/trim.hpp>
@@ -345,7 +344,7 @@ std::u16string ToUtf16(std::string_view utf8)
bool IsASCIIString(std::string_view sv)
{
for (auto c : sv)
for (auto const c : sv)
if (c & 0x80)
return false;
return true;

View File

@@ -114,6 +114,20 @@ void Trim(std::string_view & sv);
void Trim(std::string_view & s, std::string_view anyOf);
void Trim(std::string & s, std::string_view anyOf);
template <std::convertible_to<std::string_view> Utf8>
size_t CountChar(Utf8 const & utf8)
{
size_t codePoints = 0;
for (auto const c : utf8)
{
if ((c & 0xC0) != 0x80)
++codePoints;
}
return codePoints;
}
bool Truncate(std::string & utf8, size_t const maxTextLengthPlus1);
// Replace the first match of the search substring in the input with the format string.

View File

@@ -19,10 +19,6 @@
#include <ft2build.h>
#include <hb-ft.h>
#include <unicode/unistr.h>
#include <limits>
#include <sstream>
#include <string>
#include <vector>
#include FT_FREETYPE_H
#include FT_MODULE_H
@@ -600,8 +596,7 @@ FreetypeError constexpr g_FT_Errors[] =
// For SplitText it's enough to know if the last visual (first logical) segment is RTL.
allGlyphs.m_isRTL = segments.back().m_direction == HB_DIRECTION_RTL;
// TODO(AB): Check if it's slower or faster.
allGlyphs.m_glyphs.reserve(icu::UnicodeString{false, text.data(), static_cast<int32_t>(text.size())}.countChar32());
allGlyphs.m_glyphs.reserve(strings::CountChar(utf8));
for (auto const & substring : segments)
{

View File

@@ -213,7 +213,7 @@ void ReorderRTL(TextSegments & segments)
TextSegments GetTextSegments(std::string_view utf8)
{
ASSERT(!utf8.empty(), ("Shaping of empty strings is not supported"));
ASSERT(std::string::npos == utf8.find_first_of("\r\n"), ("Shaping with line breaks is not supported", utf8));
ASSERT(std::string::npos == utf8.find_first_of("\n"), ("Shaping with line breaks is not supported", utf8));
// TODO(AB): Can unnecessary conversion/allocation be avoided?
TextSegments segments{strings::ToUtf16(utf8), {}};

View File

@@ -3,7 +3,7 @@
#include "search/ranking_utils.hpp"
#include "search/token_range.hpp"
#include <map>
#include <unordered_map>
#include <sstream>
namespace search
@@ -15,7 +15,7 @@ namespace
// All synonyms should be lowercase.
/// @todo These should check the map language and use only the corresponding translation.
map<string, vector<string>> const kSynonyms = {
unordered_map<string, vector<string>> const kSynonyms = {
/// @todo Should process synonyms with errors like "blvrd" -> "blvd".
/// @see HouseOnStreetSynonymsWithMisprints test.
{"1", {"pierwszy", "pierwsza", "un", "una", "pierwsze", "primo"}},