halkyon/halkyon_learn_curator/lib/src/gloss_keys.dart

16 lines
613 B
Dart
Raw Normal View History

/// What a search for a meaning matches in [gloss], lower case: the gloss
/// without its remarks in brackets, and without a leading "to" or article
/// too (`to eat` gives `to eat` and `eat`; `the sun (in the sky)` gives
/// `the sun` and `sun`). Empty for a gloss of remarks only.
List<String> glossKeys(String gloss) {
final plain = gloss
.toLowerCase()
.replaceAll(RegExp(r'\([^)]*\)'), ' ')
.replaceAll(RegExp(r'\s+'), ' ')
.trim();
if (plain.isEmpty) {
return const [];
}
final bare = plain.replaceFirst(RegExp('^(to|a|an|the) '), '');
return {plain, bare}.toList();
}