From 039583447467d8658e758f457aacf67d83d03093 Mon Sep 17 00:00:00 2001 From: 4sterisk <4sterisk@ymail.ne.jp> Date: Mon, 18 Nov 2024 22:26:43 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E7=B5=B5?= =?UTF-8?q?=E6=96=87=E5=AD=97=E3=81=AE=E3=81=8B=E3=81=AA=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/repository/emoji_repository.dart | 42 ++++++++++++++++------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/repository/emoji_repository.dart b/lib/repository/emoji_repository.dart index f02276d35..d710f1719 100644 --- a/lib/repository/emoji_repository.dart +++ b/lib/repository/emoji_repository.dart @@ -53,6 +53,9 @@ class EmojiRepositoryImpl extends EmojiRepository { bool thisLaunchLoaded = false; + final romajiPattern = RegExp(r"^[A-Za-z0-9_+-]+$"); + final splitPattern = RegExp("[_+-]"); + String format(String emojiName) { return emojiName .replaceAll("_", "") @@ -109,7 +112,13 @@ class EmojiRepositoryImpl extends EmojiRepository { String toHiraganaSafe(String text) { try { - return const KanaKit().toHiragana(text); + if (romajiPattern.hasMatch(text)) { + return text + .split(splitPattern) + .map((e) => const KanaKit().toHiragana(e)) + .join(); + } + return const KanaKit().toHiragana(format(text)); } catch (e) { return text; } @@ -118,21 +127,18 @@ class EmojiRepositoryImpl extends EmojiRepository { Future _setEmojiData(EmojisResponse response) async { final toH = toHiraganaSafe; - final unicodeEmojis = - (jsonDecode(await rootBundle.loadString("assets/emoji_list.json")) - as List) - .map((e) => UnicodeEmoji.fromJson(e)) - .map( - (e) => EmojiRepositoryData( - emoji: UnicodeEmojiData(char: e.char), - kanaName: toH(format(e.char)), - kanaAliases: [e.name, ...e.keywords] - .map((e2) => toH(format(e2))) - .toList(), - aliases: [e.name, ...e.keywords], - category: e.category, - ), - ); + final unicodeEmojis = (jsonDecode( + await rootBundle.loadString("assets/emoji_list.json")) as List) + .map((e) => UnicodeEmoji.fromJson(e)) + .map( + (e) => EmojiRepositoryData( + emoji: UnicodeEmojiData(char: e.char), + kanaName: toH(e.char), + kanaAliases: [e.name, ...e.keywords].map((e2) => toH(e2)).toList(), + aliases: [e.name, ...e.keywords], + category: e.category, + ), + ); emoji = response.emojis .map( @@ -145,9 +151,9 @@ class EmojiRepositoryImpl extends EmojiRepository { isSensitive: e.isSensitive, ), category: e.category ?? "", - kanaName: toH(format(e.name)), + kanaName: toH(e.name), aliases: e.aliases, - kanaAliases: e.aliases.map((e2) => format(toH(e2))).toList(), + kanaAliases: e.aliases.map((e2) => toH(e2)).toList(), ), ) .toList();