Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kaboc committed May 28, 2023
1 parent 3557280 commit 2e6e112
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
23 changes: 19 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
## 2.0.0

- **Breaking**:
- `UrlMatcher` now matches only URLs starting with http(s). (#10)
- `matchers` is no longer optional. (#12)
- Non-breaking:
- Refactor the parser entirely. (#8)
- This resolves the issue that required a workaround when lookbehind assertion was used.
- Fix `UrlMatcher` to exclude backslashes.
- Add `UrlLikeMatcher` that matches URL-like strings not starting with http(s). (#10)
- This behaves the same way as `UrlMatcher` used to before this version.
- Add assertions to check matchers and patterns are not empty.
- Add and improve tests.

## 1.2.0-dev.2

- **Breaking**
- **Breaking**:
- `UrlMatcher` now matches only URLs starting with http(s). (#10)
- This also affects the behaviour of TextParser with the default matchers.
- Add `UrlLikeMatcher` that matches URL-like strings not starting with http(s).
- This behaves the same way as `UrlMatcher` used to before this version.
- Fix `UrlMatcher` to exclude backslashes.
- Non-breaking:
- Fix `UrlMatcher` to exclude backslashes.
- Add `UrlLikeMatcher` that matches URL-like strings not starting with http(s). (#10)
- This behaves the same way as `UrlMatcher` used to before this version.

## 1.2.0-dev.1

Expand Down
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Dart package for parsing text flexibly according to preset or custom regular e

## Usage

### Using preset matchers (URL / email address / phone number)
### Using the preset matchers (URL / email address / phone number)

The package has the following preset matchers.

Expand Down Expand Up @@ -88,7 +88,21 @@ Or use a classic way:
final telElements = elements.map((elm) => elm.matcherType == TelMatcher).toList();
```

### Overwriting the pattern of a preset matcher
#### Conflict between matchers

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

```dart
final parser = TextParser(matchers: const[UrlLikeMatcher(), EmailMatcher()]);
final elements = await parser.parse('foo.bar@example.com');
```

In this example, `UrlLikeMatcher` matches `foo.bar` and `EmailMatcher` matches
`foo.bar@example.com`, but `UrlLikeMatcher` is used because it is written before
`EmailMatcher` in the matchers list.

### Overwriting the pattern of an existing 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:
Expand All @@ -102,9 +116,6 @@ final parser = TextParser(
);
```

If the match patterns of multiple matchers have matched the same string at the same position
in text, the first matcher is used for parsing the element.

### Using a custom pattern

You can create a matcher with a custom pattern either with [PatternMatcher][PatternMatcher]
Expand Down
4 changes: 3 additions & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ Future<void> main() async {

// A match pattern containing capturing of unnamed and named groups
parser = TextParser(
matchers: const [PatternMatcher(r'(?<year>\d{4})-(\d{2})-(?<day>\d{2})')],
matchers: const [
PatternMatcher(r'(?<year>\d{4})-(\d{2})-(?<day>\d{2})'),
],
);
elements = await parser.parse('2020-01-23', onlyMatches: true);
elements.forEach(print);
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: text_parser_example
description: An example of text_parser.

environment:
sdk: '>=2.18.0 <3.0.0'
sdk: '>=2.18.0 <4.0.0'

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

environment:
sdk: '>=2.18.0 <3.0.0'
sdk: '>=2.18.0 <4.0.0'

dependencies:
meta: ^1.8.0

dev_dependencies:
lints: ^2.0.1
test: ^1.23.1
test: ^1.24.3

0 comments on commit 2e6e112

Please sign in to comment.