From fc0956d5c3ae986d089b7b11131544a03ee174a7 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 16 May 2025 17:05:57 +0200 Subject: [PATCH] lib/text_filtering: add kanjiRegex --- lib/util/text_filtering.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/util/text_filtering.dart b/lib/util/text_filtering.dart index 3a49c76..c3b4e59 100644 --- a/lib/util/text_filtering.dart +++ b/lib/util/text_filtering.dart @@ -4,7 +4,7 @@ /// See https://www.regular-expressions.info/unicode.html /// /// Remember to turn on the unicode flag when making a new RegExp. -const String rawKanjiRegex = r'\p{Script=Hani}'; +const String rawCJKRegex = r'\p{Script=Hani}'; /// The string version of a regex that will match any katakana. /// This includes the ranges (), () @@ -22,14 +22,22 @@ const String rawKatakanaRegex = r'\p{Script=Katakana}'; /// Remember to turn on the unicode flag when making a new RegExp. const String rawHiraganaRegex = r'\p{Script=Hiragana}'; +/// The string version of a regex that will match any kanji. +/// This includes the ranges (), () +/// +/// See https://www.regular-expressions.info/unicode.html +/// +/// Remember to turn on the unicode flag when making a new RegExp. +const String rawKanjiRegex = r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]'; -final RegExp kanjiRegex = RegExp(rawKanjiRegex, unicode: true); + +final RegExp cjkRegex = RegExp(rawCJKRegex, unicode: true); final RegExp katakanaRegex = RegExp(rawKatakanaRegex, unicode: true); final RegExp hiraganaRegex = RegExp(rawHiraganaRegex, unicode: true); +final RegExp kanjiRegex = RegExp(rawKanjiRegex, unicode: true); -final kanjiPattern = RegExp(r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]'); List filterKanjiSuggestions(String string) { - return kanjiPattern + return kanjiRegex .allMatches(string) .map((match) => match.group(0)) .where((element) => element != null)