summaryrefslogtreecommitdiff
path: root/src/database/index.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-10-30 15:47:38 +1100
committerjacqueline <me@jacqueline.id.au>2023-10-30 15:52:26 +1100
commitb58c08150853b8055093dc116d407ffd543f8ec8 (patch)
tree9b82d130d2c833fc234bca0f12f0fba1b7202c4d /src/database/index.cpp
parent18d90051c9145ead86d4da701a2bc54f45e4fb66 (diff)
downloadtangara-fw-b58c08150853b8055093dc116d407ffd543f8ec8.tar.gz
add locale-aware colation to db indexes
Diffstat (limited to 'src/database/index.cpp')
-rw-r--r--src/database/index.cpp10
1 files changed, 6 insertions, 4 deletions
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 <cstdint>
+#include <sstream>
#include <variant>
+#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::pair<IndexKey, std::pmr::string>> {
std::vector<std::pair<IndexKey, std::pmr::string>> out;
IndexKey key{
@@ -72,15 +75,14 @@ auto Index(const IndexInfo& info, const Track& t)
.track = {},
};
- auto& col = std::use_facet<std::collate<char>>(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 = {};