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/locale/include/collation.hpp | 49 ++++++++++++++++++++++++++++++++++++++++ src/locale/include/strxfrm.h | 35 ++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 src/locale/include/collation.hpp create mode 100644 src/locale/include/strxfrm.h (limited to 'src/locale/include') diff --git a/src/locale/include/collation.hpp b/src/locale/include/collation.hpp new file mode 100644 index 00000000..e8b6fa17 --- /dev/null +++ b/src/locale/include/collation.hpp @@ -0,0 +1,49 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include +#include + +#include "esp_partition.h" +#include "span.hpp" + +#include "strxfrm.h" + +namespace locale { + +class ICollator { + public: + virtual ~ICollator() {} + + virtual auto Transform(const std::string&) -> std::string = 0; +}; + +class NoopCollator : public ICollator { + public: + auto Transform(const std::string& in) -> std::string override { return in; } +}; + +auto CreateCollator() -> std::unique_ptr; + +class GLibCollator : public ICollator { + public: + static auto create() -> GLibCollator*; + ~GLibCollator(); + + auto Transform(const std::string& in) -> std::string override; + + private: + GLibCollator(const esp_partition_mmap_handle_t, + std::unique_ptr); + + const esp_partition_mmap_handle_t handle_; + std::unique_ptr locale_data_; +}; + +} // namespace locale diff --git a/src/locale/include/strxfrm.h b/src/locale/include/strxfrm.h new file mode 100644 index 00000000..a40f7596 --- /dev/null +++ b/src/locale/include/strxfrm.h @@ -0,0 +1,35 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + uint_fast32_t nrules; + unsigned char* rulesets; + unsigned char* weights; + int32_t* table; + unsigned char* extra; + int32_t* indirect; +} locale_data_t; + +bool parse_locale_data(const void* raw_data, size_t size, locale_data_t* out); + +size_t glib_strxfrm(char* dest, + const char* src, + size_t n, + locale_data_t* locale); + +#ifdef __cplusplus +} +#endif -- cgit v1.2.3