Export reused kanji regex into own file

This commit is contained in:
Oystein Kristoffer Tveit 2022-05-01 23:33:45 +02:00
parent 8c7253fd93
commit eaa5510942
3 changed files with 6 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:jisho_study_tool/services/kanji_regex.dart';
import 'package:unofficial_jisho_api/api.dart';
import '../../../../models/themes/theme.dart';
@ -34,8 +35,8 @@ class KanjiKanaBox extends StatelessWidget {
bool get hasFurigana => word.reading != null;
String get kana => '${word.reading ?? ""}${word.word ?? ""}'
.replaceAll(RegExp(r'\p{Script=Hani}', unicode: true), '');
String get kana =>
'${word.reading ?? ""}${word.word ?? ""}'.replaceAll(kanjiRegex, '');
@override
Widget build(BuildContext context) {

View File

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:jisho_study_tool/services/kanji_regex.dart';
import 'package:unofficial_jisho_api/api.dart';
import './parts/common_badge.dart';
@ -55,7 +56,7 @@ class _SearchResultCardState extends State<SearchResultCard> {
return jlpt.last;
}
List<String> get kanji => RegExp(r'(\p{Script=Hani})', unicode: true)
List<String> get kanji => kanjiRegex
.allMatches(
widget.result.japanese
.map((w) => '${w.word ?? ""}${w.reading ?? ""}')

View File

@ -0,0 +1 @@
final kanjiRegex = RegExp(r'\p{Script=Hani}', unicode: true);