Skip to content

Commit

Permalink
2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaboc committed Dec 14, 2024
1 parent ce18911 commit 975541b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ doc/

# Mac
.DS_Store

# Others
.fvm/
.fvmrc
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2.4.0

- Bump minimum Dart SDK version to 3.2.0.
- Add `parseSync()` to TextParser.
- Update tests to use `parseSync()` instead of `parse()`.
- Refactorings:
- Rename internal `Parser` to `ParserBody`.
- Add new `Parser` extending `ParserBody` to each of the files for web and non-web.
- Move TextParser from the root to `src/`.

## 2.3.0

- Change `matchers` of TextParser from `List` to `Iterable`.
Expand Down
37 changes: 11 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ TextElement(matcherType: TelMatcher, matcherIndex 2, offset: 61, text: +1-012-34
```

The regular expression pattern of each of them is not very strict. If it does not meet
your use case, overwrite the pattern by yourself to make it stricter, referring to the
relevant section later in this document.
your use case, overwrite the pattern by yourself to make it stricter.

#### parse() vs parseSync()

Expand All @@ -71,8 +70,8 @@ etc). If you want them to be matched too, use [UrlLikeMatcher] instead.

#### matcherType and matcherIndex

`matcherType` contained in a [TextElement] object is the type of the matcher used
to parse the text into the element. `matcherIndex` is the index of the matcher in
`matcherType` contained in a [TextElement] object is the type of the matcher that
was used to extract the element. `matcherIndex` is the index of the matcher in
the matcher list passed to the `matchers` argument of [TextParser].

#### Extracting only matching text elements
Expand Down Expand Up @@ -109,7 +108,7 @@ final telElements = elements.map((elm) => elm.matcherType == TelMatcher).toList(

#### Conflict between matchers

If multiple matchers have matched the string at the same position in text, the first one
If multiple matchers match the string at the same position in text, the first one
in those matchers takes precedence.

```dart
Expand All @@ -121,18 +120,12 @@ In this example, `UrlLikeMatcher` matches `foo.bar` and `EmailMatcher` matches
`[email protected]`, but `UrlLikeMatcher` is used because it is written before
`EmailMatcher` in the matchers list.

### Overwriting the pattern of an existing matcher
### Overwriting the pattern of a preset matcher

If you want to parse only URLs and phone numbers, but treat only a sequence of eleven numbers
after "tel:" as a phone number:
If you want to parse a sequence of eleven numbers after "tel:" as a phone number:

```dart
final parser = TextParser(
matchers: const [
UrlMatcher(),
TelMatcher(r'(?<=tel:)\d{11}'),
],
);
TelMatcher(r'(?<=tel:)\d{11}')
```

### Using a custom pattern
Expand Down Expand Up @@ -189,8 +182,8 @@ Output:
### ExactMatcher

`ExactMatcher` escapes reserved characters of RegExp so that those are used
as ordinary characters. The parser extracts the substrings that exactly match
any of the strings in the passed list.
as regular characters. The parser extracts the substrings that exactly match
any of the strings in the list passed as the argument.

```dart
TextParser(
Expand Down Expand Up @@ -251,16 +244,8 @@ How a regular expression is treated can be configured in the `TextParser` constr
- unicode
- dotAll

These options are passed to [RegExp][RegExp] internally, so refer to its
[document][RegExp_constructor] for information.

## Limitations

- This package uses regular expressions. The speed of parsing is subject to the
performance of `RegExp` in Dart. It will take more time to parse longer text with
multiple complex match patterns.
- On the web, parsing is always executed in the main thread because Flutter Web does
not support [dart:isolate][isolate].
These options are passed to the constructor of [RegExp][RegExp] internally, so
refer to its [document][RegExp_constructor] for information.

[TextParser]: https://pub.dev/documentation/text_parser/latest/text_parser/TextParser-class.html
[TextParser_matchers]: https://pub.dev/documentation/text_parser/latest/text_parser/TextParser/matchers.html
Expand Down
1 change: 0 additions & 1 deletion lib/src/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ extension on List<String?> {
return false;
}
}

return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/parser_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class ParserBody {
final bool dotAll;

late Iterable<TextMatcher> _matchers;
late String _pattern;
final List<String> _matcherGroupNames = [];
final List<List<int>> _matcherGroupRanges = [];
late String _pattern;

List<TextMatcher> get matchers => List.unmodifiable(_matchers);

Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: text_parser
description: A Dart package for flexibly parsing text into easy-to-handle format according to multiple regular expression patterns.
version: 2.3.0
version: 2.4.0
repository: https://github.com/kaboc/dart_text_parser

topics:
- text
- parser
- parsing

environment:
sdk: '>=3.2.0 <4.0.0'
Expand Down

0 comments on commit 975541b

Please sign in to comment.