Skip to content

Commit

Permalink
run dartfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-r-warren committed May 18, 2019
1 parent 36b6d93 commit bc9df8c
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 69 deletions.
3 changes: 2 additions & 1 deletion example/date_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import 'package:best_effort_parser/date.dart';
/// $ dart date_example.dart 'January 1st, 2019'
/// [Day]: 1 [Month]: 1 [Year]: 2019
/// ```
void main(List<String> arguments) => DateParser.basic().parse(arguments.join(' ')).forEach(print);
void main(List<String> arguments) =>
DateParser.basic().parse(arguments.join(' ')).forEach(print);
10 changes: 7 additions & 3 deletions lib/date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ class DateParser<T> {
final List<int> dayParts = [], monthParts = [], yearParts = [];

// collect parts
RegExp(r'((?:[\d]+\D){2}[\d]+)|([^\W_]+)').allMatches(text).forEach((Match match) {
RegExp(r'((?:[\d]+\D){2}[\d]+)|([^\W_]+)')
.allMatches(text)
.forEach((Match match) {
if (match.group(1) != null) {
// Compact format matching ((?:[\d]+\D){2}[\d]+), like `MM/DD/YY`
final numbers = RegExp(r'(\d+)')
Expand Down Expand Up @@ -271,7 +273,8 @@ class DateParser<T> {
if (_seasons.isNotEmpty && _seasonToMonth != null) {
for (int s = 0; s < _seasons.length; s++) {
if (part.contains(_seasons[s])) {
monthParts.add(_seasonToMonth[s + 1] ?? defaultSeasonToMonthApproximations[s + 1]);
monthParts.add(_seasonToMonth[s + 1] ??
defaultSeasonToMonthApproximations[s + 1]);
}
}
}
Expand Down Expand Up @@ -323,7 +326,8 @@ class DateParser<T> {

/// Turn [year] into a four digit number if necessary and possible.
int _toYear(int year) {
if (year.toString().length < 4 && _fourDigitOffsets.firstKeyAfter(year) != null) {
if (year.toString().length < 4 &&
_fourDigitOffsets.firstKeyAfter(year) != null) {
return year + _fourDigitOffsets[_fourDigitOffsets.firstKeyAfter(year)];
} else {
return year;
Expand Down
25 changes: 18 additions & 7 deletions lib/name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import 'src/name/parsed_name.dart';
/// The values given as parameters to this function will never be null. If a name does not have a
/// given component, an empty string will be given to this function's corresponding parameter.
typedef NameParserOutput<T> = T Function(String family,
{String given, String droppingParticle, String nonDroppingParticle, String suffix});
{String given,
String droppingParticle,
String nonDroppingParticle,
String suffix});

/// A parser designed to extract a person's name from an arbitrary string. The [parse] method
/// will create a [T] object with the person's family name, given name, particles (dropping and
Expand Down Expand Up @@ -48,7 +51,8 @@ class NameParser<T> {
/// - `jr`, `sr`
/// - Roman numerals `i` - `xiii`
/// - `esq`, `cpa`, `dc`, `dds`, `vm`, `jd`, `md`, `phd`
static const String defaultSuffixes = r'^([js]r|[vx]?i{0,3}|i[vx]|esq|cpa|dc|dds|vm|[jm]d|phd)$';
static const String defaultSuffixes =
r'^([js]r|[vx]?i{0,3}|i[vx]|esq|cpa|dc|dds|vm|[jm]d|phd)$';

/// A [RegExp] pattern matching a variety of name particles.
///
Expand Down Expand Up @@ -91,9 +95,14 @@ class NameParser<T> {
Pattern particles = defaultParticles,
Pattern punctuation = defaultPunctuation}) {
_nameParserOutput = nameParserOutput;
_suffixes = suffixes is String ? RegExp(suffixes, caseSensitive: false) : suffixes;
_particles = particles is String ? RegExp(particles, caseSensitive: false) : particles;
_punctuation = punctuation is String ? RegExp(punctuation, caseSensitive: false) : punctuation;
_suffixes =
suffixes is String ? RegExp(suffixes, caseSensitive: false) : suffixes;
_particles = particles is String
? RegExp(particles, caseSensitive: false)
: particles;
_punctuation = punctuation is String
? RegExp(punctuation, caseSensitive: false)
: punctuation;
}

/// Static basic constructor for [NameParser] that restricts the output of [parse] to be a
Expand Down Expand Up @@ -153,7 +162,8 @@ class NameParser<T> {
.replaceAll(_punctuation, '')
.contains(_suffixes)) {
List<String> lastParts = nonSuffixParts.removeLast().split(_whitespace);
while (lastParts.last.replaceAll(_punctuation, '').contains(_suffixes)) {
while (
lastParts.last.replaceAll(_punctuation, '').contains(_suffixes)) {
suffixParts.addFirst(lastParts.removeLast());
}
nonSuffixParts.add(lastParts.join(' '));
Expand Down Expand Up @@ -199,7 +209,8 @@ class NameParser<T> {
// dropping.
DoubleLinkedQueue<String> nonDroppingParticleParts = DoubleLinkedQueue();
DoubleLinkedQueue<String> droppingParticleParts = DoubleLinkedQueue();
while (spaceParts.isNotEmpty && spacePartsNoPunctuation.last.contains(_particles)) {
while (spaceParts.isNotEmpty &&
spacePartsNoPunctuation.last.contains(_particles)) {
var particle = spacePartsNoPunctuation.removeLast();
if (particle.toLowerCase() != particle) {
nonDroppingParticleParts.addFirst(spaceParts.removeLast());
Expand Down
5 changes: 4 additions & 1 deletion lib/src/date/parsed_date.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class ParsedDate {
/// Evaluate if the [other] object is the same as this, by type and field equality.
@override
bool operator ==(other) =>
other is ParsedDate && year == other.year && month == other.month && day == other.day;
other is ParsedDate &&
year == other.year &&
month == other.month &&
day == other.day;

/// Alias [toString] to [diagnosticString], forcing default parameters.
@override
Expand Down
16 changes: 12 additions & 4 deletions lib/src/name/parsed_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class ParsedName {
/// Constructor for [ParsedName], where any null parameters will have the empty string used in
/// their place.
ParsedName(String family,
{String given, String droppingParticle, String nonDroppingParticle, String suffix}) {
{String given,
String droppingParticle,
String nonDroppingParticle,
String suffix}) {
_family = family ?? '';
_given = given ?? '';
_droppingParticle = droppingParticle ?? '';
Expand All @@ -31,7 +34,10 @@ class ParsedName {
/// Static method constructor for [ParsedName] so that this class can be constructed via
/// reference.
static ParsedName constantConstructor(String family,
{String given, String droppingParticle, String nonDroppingParticle, String suffix}) =>
{String given,
String droppingParticle,
String nonDroppingParticle,
String suffix}) =>
ParsedName(family,
given: given,
droppingParticle: droppingParticle,
Expand Down Expand Up @@ -76,9 +82,11 @@ class ParsedName {
[
if (given.isNotEmpty && givenLabel.isNotEmpty) givenLabel,
if (given.isNotEmpty) given,
if (droppingParticle.isNotEmpty && droppingParticleLabel.isNotEmpty) droppingParticleLabel,
if (droppingParticle.isNotEmpty && droppingParticleLabel.isNotEmpty)
droppingParticleLabel,
if (droppingParticle.isNotEmpty) droppingParticle,
if (nonDroppingParticle.isNotEmpty && nonDroppingParticleLabel.isNotEmpty)
if (nonDroppingParticle.isNotEmpty &&
nonDroppingParticleLabel.isNotEmpty)
nonDroppingParticleLabel,
if (nonDroppingParticle.isNotEmpty) nonDroppingParticle,
if (family.isNotEmpty && familyLabel.isNotEmpty) familyLabel,
Expand Down

0 comments on commit bc9df8c

Please sign in to comment.