mirror of
https://github.com/go-vikunja/app
synced 2024-06-05 03:59:48 +00:00
056b2d72c9
This PR formats all code with dart format and adds a step to the CI so that it will be checked on every push and PR.
49 lines
1.0 KiB
Dart
49 lines
1.0 KiB
Dart
class CheckboxStatistics {
|
|
final int total;
|
|
final int checked;
|
|
|
|
const CheckboxStatistics({
|
|
required this.total,
|
|
required this.checked,
|
|
});
|
|
}
|
|
|
|
class MatchedCheckboxes {
|
|
final Iterable<Match> checked;
|
|
final Iterable<Match> unchecked;
|
|
|
|
const MatchedCheckboxes({
|
|
required this.checked,
|
|
required this.unchecked,
|
|
});
|
|
}
|
|
|
|
MatchedCheckboxes getCheckboxesInText(String text) {
|
|
const checkedString = '[x]';
|
|
final checked = <Match>[];
|
|
final unchecked = <Match>[];
|
|
|
|
final matches = RegExp(r'[*-] \[[ x]]').allMatches(text);
|
|
|
|
for (final match in matches) {
|
|
if (match[0]?.endsWith(checkedString) ?? false)
|
|
checked.add(match);
|
|
else
|
|
unchecked.add(match);
|
|
}
|
|
|
|
return MatchedCheckboxes(
|
|
checked: checked,
|
|
unchecked: unchecked,
|
|
);
|
|
}
|
|
|
|
CheckboxStatistics getCheckboxStatistics(String text) {
|
|
final checkboxes = getCheckboxesInText(text);
|
|
|
|
return CheckboxStatistics(
|
|
total: checkboxes.checked.length + checkboxes.unchecked.length,
|
|
checked: checkboxes.checked.length,
|
|
);
|
|
}
|