mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:57:35 +00:00
LibUnicode: Add to-and-from string converters for NormalizationForm
This commit is contained in:
parent
462c49ad55
commit
19b758ce8b
2 changed files with 31 additions and 0 deletions
|
@ -17,6 +17,34 @@ namespace Unicode {
|
||||||
Optional<CodePointDecomposition const&> __attribute__((weak)) code_point_decomposition(u32) { return {}; }
|
Optional<CodePointDecomposition const&> __attribute__((weak)) code_point_decomposition(u32) { return {}; }
|
||||||
Span<CodePointDecomposition const> __attribute__((weak)) code_point_decompositions() { return {}; }
|
Span<CodePointDecomposition const> __attribute__((weak)) code_point_decompositions() { return {}; }
|
||||||
|
|
||||||
|
NormalizationForm normalization_form_from_string(StringView form)
|
||||||
|
{
|
||||||
|
if (form == "NFD"sv)
|
||||||
|
return NormalizationForm::NFD;
|
||||||
|
if (form == "NFC"sv)
|
||||||
|
return NormalizationForm::NFC;
|
||||||
|
if (form == "NFKD"sv)
|
||||||
|
return NormalizationForm::NFKD;
|
||||||
|
if (form == "NFKC"sv)
|
||||||
|
return NormalizationForm::NFKC;
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
StringView normalization_form_to_string(NormalizationForm form)
|
||||||
|
{
|
||||||
|
switch (form) {
|
||||||
|
case NormalizationForm::NFD:
|
||||||
|
return "NFD"sv;
|
||||||
|
case NormalizationForm::NFC:
|
||||||
|
return "NFC"sv;
|
||||||
|
case NormalizationForm::NFKD:
|
||||||
|
return "NFKD"sv;
|
||||||
|
case NormalizationForm::NFKC:
|
||||||
|
return "NFKC"sv;
|
||||||
|
}
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
|
|
||||||
ALWAYS_INLINE static bool is_starter(u32 code_point)
|
ALWAYS_INLINE static bool is_starter(u32 code_point)
|
||||||
{
|
{
|
||||||
return Unicode::canonical_combining_class(code_point) == 0;
|
return Unicode::canonical_combining_class(code_point) == 0;
|
||||||
|
|
|
@ -25,6 +25,9 @@ enum class NormalizationForm {
|
||||||
NFKC
|
NFKC
|
||||||
};
|
};
|
||||||
|
|
||||||
|
NormalizationForm normalization_form_from_string(StringView form);
|
||||||
|
StringView normalization_form_to_string(NormalizationForm form);
|
||||||
|
|
||||||
[[nodiscard]] String normalize(StringView string, NormalizationForm form);
|
[[nodiscard]] String normalize(StringView string, NormalizationForm form);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue