Skip to content

Commit

Permalink
カスタム絵文字のかな変換の調整
Browse files Browse the repository at this point in the history
  • Loading branch information
4ster1sk committed Nov 18, 2024
1 parent 690c8f9 commit 6b52437
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/repository/emoji_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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("_", "")
Expand Down Expand Up @@ -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;
}
Expand All @@ -125,9 +134,9 @@ class EmojiRepositoryImpl extends EmojiRepository {
.map(
(e) => EmojiRepositoryData(
emoji: UnicodeEmojiData(char: e.char),
kanaName: toH(format(e.char)),
kanaName: toH(e.char),
kanaAliases: [e.name, ...e.keywords]
.map((e2) => toH(format(e2)))
.map((e2) => toH(e2))
.toList(),
aliases: [e.name, ...e.keywords],
category: e.category,
Expand All @@ -145,9 +154,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();
Expand Down

0 comments on commit 6b52437

Please sign in to comment.