From b58c08150853b8055093dc116d407ffd543f8ec8 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 30 Oct 2023 15:47:38 +1100 Subject: add locale-aware colation to db indexes --- src/database/index.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/database/index.cpp') diff --git a/src/database/index.cpp b/src/database/index.cpp index 84ea050a..7d556192 100644 --- a/src/database/index.cpp +++ b/src/database/index.cpp @@ -7,8 +7,11 @@ #include "index.hpp" #include +#include #include +#include "collation.hpp" +#include "esp_log.h" #include "komihash.h" #include "leveldb/write_batch.h" @@ -59,7 +62,7 @@ static auto missing_component_text(const Track& track, Tag tag) } } -auto Index(const IndexInfo& info, const Track& t) +auto Index(locale::ICollator& collator, const IndexInfo& info, const Track& t) -> std::vector> { std::vector> out; IndexKey key{ @@ -72,15 +75,14 @@ auto Index(const IndexInfo& info, const Track& t) .track = {}, }; - auto& col = std::use_facet>(std::locale()); - for (std::uint8_t i = 0; i < info.components.size(); i++) { // Fill in the text for this depth. auto text = t.tags().at(info.components.at(i)); std::pmr::string value; if (text) { std::pmr::string orig = *text; - key.item = col.transform(&orig[0], &orig[0] + orig.size()); + auto xfrm = collator.Transform({orig.data(), orig.size()}); + key.item = {xfrm.data(), xfrm.size()}; value = *text; } else { key.item = {}; -- cgit v1.2.3