Skip to content

Commit

Permalink
Require unicode attribute to be passed on all internal methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
renggli committed Jan 2, 2025
1 parent 1d0c1c6 commit b0c18f7
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/src/parser/character/utils/optimize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import '../predicates/lookup.dart';
import '../predicates/range.dart';

/// Creates an optimized character from a string.
CharacterPredicate optimizedString(String string, {bool unicode = false}) =>
optimizedRanges((unicode ? string.runes : string.codeUnits)
.map((value) => RangeCharPredicate(value, value)));
CharacterPredicate optimizedString(String string, {required bool unicode}) =>
optimizedRanges(
(unicode ? string.runes : string.codeUnits)
.map((value) => RangeCharPredicate(value, value)),
unicode: unicode);

/// Creates an optimized predicate from a list of range predicates.
CharacterPredicate optimizedRanges(Iterable<RangeCharPredicate> ranges,
{bool unicode = false}) {
{required bool unicode}) {
// 1. Sort the ranges:
final sortedRanges = List.of(ranges, growable: false);
sortedRanges.sort((first, second) => first.start != second.start
Expand Down

0 comments on commit b0c18f7

Please sign in to comment.