diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-10-30 15:47:38 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-10-30 15:52:26 +1100 |
| commit | b58c08150853b8055093dc116d407ffd543f8ec8 (patch) | |
| tree | 9b82d130d2c833fc234bca0f12f0fba1b7202c4d /src/locale/include | |
| parent | 18d90051c9145ead86d4da701a2bc54f45e4fb66 (diff) | |
| download | tangara-fw-b58c08150853b8055093dc116d407ffd543f8ec8.tar.gz | |
add locale-aware colation to db indexes
Diffstat (limited to 'src/locale/include')
| -rw-r--r-- | src/locale/include/collation.hpp | 49 | ||||
| -rw-r--r-- | src/locale/include/strxfrm.h | 35 |
2 files changed, 84 insertions, 0 deletions
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 <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <cstddef> +#include <memory> +#include <string> + +#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<ICollator>; + +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<locale_data_t>); + + const esp_partition_mmap_handle_t handle_; + std::unique_ptr<locale_data_t> 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 <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +#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 |
