From 4cc5fa4c9c324c18908a7786358c7f6cac8a7f82 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 31 Oct 2023 09:01:34 +1100 Subject: Store the current collator in the database --- src/locale/collation.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/locale/collation.cpp') diff --git a/src/locale/collation.cpp b/src/locale/collation.cpp index f5e8272a..2d787b5a 100644 --- a/src/locale/collation.cpp +++ b/src/locale/collation.cpp @@ -58,19 +58,26 @@ auto GLibCollator::create() -> GLibCollator* { return nullptr; } + // We reserve the first 8 bytes of the partition for an identifier / name. + // Copy it out, then crop the rest of the region so that the LC_COLLATE parser + // doesn't see it. + std::string name{static_cast(region)}; + region = static_cast(region) + 8; + auto data = std::make_unique(); - if (!parse_locale_data(region, partition->size, data.get())) { + if (!parse_locale_data(region, partition->size - 8, data.get())) { ESP_LOGE(kTag, "parsing locale data failed"); esp_partition_munmap(handle); return nullptr; } - return new GLibCollator(handle, std::move(data)); + return new GLibCollator(name, handle, std::move(data)); } -GLibCollator::GLibCollator(const esp_partition_mmap_handle_t handle, +GLibCollator::GLibCollator(const std::string& name, + const esp_partition_mmap_handle_t handle, std::unique_ptr locale) - : handle_(handle), locale_data_(std::move(locale)) {} + : name_(name), handle_(handle), locale_data_(std::move(locale)) {} GLibCollator::~GLibCollator() { esp_partition_munmap(handle_); -- cgit v1.2.3