diff --git a/.gitignore b/.gitignore index a401266..f1e4f28 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,7 @@ doc/ # Mac .DS_Store + +# Others +.fvm/ +.fvmrc diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cb11c0..6d9df8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/README.md b/README.md index f697a5d..c1e0b7b 100644 --- a/README.md +++ b/README.md @@ -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() @@ -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 @@ -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 @@ -121,18 +120,12 @@ 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 +### 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 @@ -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( @@ -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 diff --git a/lib/src/element.dart b/lib/src/element.dart index 0842c64..fe0ad2d 100644 --- a/lib/src/element.dart +++ b/lib/src/element.dart @@ -113,7 +113,6 @@ extension on List { return false; } } - return true; } } diff --git a/lib/src/parser_body.dart b/lib/src/parser_body.dart index 2655cb4..eed0f8c 100644 --- a/lib/src/parser_body.dart +++ b/lib/src/parser_body.dart @@ -20,9 +20,9 @@ class ParserBody { final bool dotAll; late Iterable _matchers; + late String _pattern; final List _matcherGroupNames = []; final List> _matcherGroupRanges = []; - late String _pattern; List get matchers => List.unmodifiable(_matchers); diff --git a/pubspec.yaml b/pubspec.yaml index 3626612..51afa0c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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'