From 1bbe8309d4e62e385dbc6b5fb8ab8373a38e4d34 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 21 Oct 2024 16:29:16 -0400 Subject: [PATCH] LibUnicode: Add a helper to determine if a code point is printable --- Userland/Libraries/LibUnicode/CharacterTypes.cpp | 5 +++++ Userland/Libraries/LibUnicode/CharacterTypes.h | 1 + 2 files changed, 6 insertions(+) diff --git a/Userland/Libraries/LibUnicode/CharacterTypes.cpp b/Userland/Libraries/LibUnicode/CharacterTypes.cpp index e96e263447c..6bb304dcedb 100644 --- a/Userland/Libraries/LibUnicode/CharacterTypes.cpp +++ b/Userland/Libraries/LibUnicode/CharacterTypes.cpp @@ -108,6 +108,11 @@ bool code_point_has_general_category(u32 code_point, GeneralCategory general_cat return u_charType(icu_code_point) == icu_general_category; } +bool code_point_is_printable(u32 code_point) +{ + return static_cast(u_isprint(static_cast(code_point))); +} + bool code_point_has_control_general_category(u32 code_point) { return code_point_has_general_category(code_point, U_CONTROL_CHAR); diff --git a/Userland/Libraries/LibUnicode/CharacterTypes.h b/Userland/Libraries/LibUnicode/CharacterTypes.h index 84dc8b6992a..c16ee908599 100644 --- a/Userland/Libraries/LibUnicode/CharacterTypes.h +++ b/Userland/Libraries/LibUnicode/CharacterTypes.h @@ -17,6 +17,7 @@ namespace Unicode { Optional general_category_from_string(StringView); bool code_point_has_general_category(u32 code_point, GeneralCategory general_category); +bool code_point_is_printable(u32 code_point); bool code_point_has_control_general_category(u32 code_point); bool code_point_has_letter_general_category(u32 code_point); bool code_point_has_number_general_category(u32 code_point);