mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibJS+LibUnicode: Fully implement Intl.Collator with ICU
We were never able to implement anything other than a basic, locale- unaware collator with the JSON export of the CLDR as it did not have collation data. We can now use ICU to implement collation.
This commit is contained in:
parent
dc0d5da086
commit
eb7e3583c9
Notes:
github-actions[bot]
2024-08-15 11:45:44 +00:00
Author: https://github.com/trflynn89
Commit: eb7e3583c9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1078
Reviewed-by: https://github.com/awesomekling
11 changed files with 384 additions and 142 deletions
62
Userland/Libraries/LibUnicode/Collator.h
Normal file
62
Userland/Libraries/LibUnicode/Collator.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/StringView.h>
|
||||
|
||||
namespace Unicode {
|
||||
|
||||
enum class Usage {
|
||||
Sort,
|
||||
Search,
|
||||
};
|
||||
Usage usage_from_string(StringView);
|
||||
StringView usage_to_string(Usage);
|
||||
|
||||
enum class Sensitivity {
|
||||
Base,
|
||||
Accent,
|
||||
Case,
|
||||
Variant,
|
||||
};
|
||||
Sensitivity sensitivity_from_string(StringView);
|
||||
StringView sensitivity_to_string(Sensitivity);
|
||||
|
||||
enum class CaseFirst {
|
||||
Upper,
|
||||
Lower,
|
||||
False,
|
||||
};
|
||||
CaseFirst case_first_from_string(StringView);
|
||||
StringView case_first_to_string(CaseFirst);
|
||||
|
||||
class Collator {
|
||||
public:
|
||||
static NonnullOwnPtr<Collator> create(
|
||||
StringView locale,
|
||||
Usage,
|
||||
StringView collation,
|
||||
Sensitivity,
|
||||
CaseFirst,
|
||||
bool numeric,
|
||||
bool ignore_punctuation);
|
||||
|
||||
virtual ~Collator() = default;
|
||||
|
||||
enum class Order {
|
||||
Before,
|
||||
Equal,
|
||||
After,
|
||||
};
|
||||
virtual Order compare(StringView, StringView) const = 0;
|
||||
|
||||
protected:
|
||||
Collator() = default;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue