瀏覽代碼

LibUnicode: Add a helper to determine if a code point is printable

Timothy Flynn 9 月之前
父節點
當前提交
1bbe8309d4
共有 2 個文件被更改,包括 6 次插入0 次删除
  1. 5 0
      Userland/Libraries/LibUnicode/CharacterTypes.cpp
  2. 1 0
      Userland/Libraries/LibUnicode/CharacterTypes.h

+ 5 - 0
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<bool>(u_isprint(static_cast<UChar32>(code_point)));
+}
+
 bool code_point_has_control_general_category(u32 code_point)
 {
     return code_point_has_general_category(code_point, U_CONTROL_CHAR);

+ 1 - 0
Userland/Libraries/LibUnicode/CharacterTypes.h

@@ -17,6 +17,7 @@ namespace Unicode {
 Optional<GeneralCategory> 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);