rich_string_parser 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

rich_string_parser #

Parse multible different values in one string.

install #

dependencies:
  rich_string_parser: ^1.0.0

Usage #

A simple usage example:

import 'package:rich_string_parser/rich_string_parser.dart';

main() {
  List<dynamic> result = richStringParser(
    'text to be parsed example@example.com @(123|example)',
    [
      EmailParser(),
      LinkParser(),
      MentionParser(),
    ]
  );

  print(result); // >> ['text to be parsed ' Instance of 'EmailMatch', ' ', Instance of 'MentionMatch']
}

Create own parser #

import 'package:rich_string_parser/rich_string_parser.dart';

class OwnMatch extends ParserMatch {
  String value;
  OwnMatch(
    this.value,
  );
}

class OwnParser extends Parser {
  RegExp regex = RegExp(
    '(hello)',
    multiLine: true,
    unicode: true
  );

  @override
  OwnMatch converter(String own) {
    return OwnMatch(
      own
    );
  }
}

main() {
  List<dynamic> result = richStringParser(
    'text to be parsed (hello)',
    [
      EmailParser(),
      LinkParser(),
      OwnParser(),
    ]
  );

  print(result); // >> ['text to be parsed ', Instance of 'OwnMatch']
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

1.0.0 #

  • Initial version, created by Stagehand

1.0.1 #

  • performance improvements and refactoring

example/rich_string_parser_example.dart

import 'package:rich_string_parser/rich_string_parser.dart';

class OwnMatch extends ParserMatch {
  String match;
  OwnMatch(
    this.match,
  ): super(match);
}

class OwnParser extends Parser {
  RegExp regex = RegExp(
    '(hello)',
    multiLine: true,
    unicode: true
  );

  @override
  OwnMatch converter(String own) {
    return OwnMatch(
      own
    );
  }
}

void main() {
  // single parser
  var singleParser = 'hello world example@example.com asd';
  List<dynamic> singleParserResult = richStringParser(
    singleParser,
    [ EmailParser() ]
  );

  // => ['hello world ', Instance of 'EmailMatch', ' asd']
  print(singleParserResult);

  // single parser
  var multibleParsers = 'hello @(123|example) world example@example.com asd';
  List<dynamic> multibleParsersResult = richStringParser(
    multibleParsers,
    [ EmailParser(), MentionParser() ]
  );

  // => ['hello ', Instance of 'MentionMatch', ' world ',  Instance of 'EmailMatch', ' asd']
  print(multibleParsersResult);

  // createParser: see OwnParser
  var own = 'hello world';
  List<dynamic> ownResult = richStringParser(
    own,
    [ OwnParser() ]
  );

  // => [Instance of 'OwnMatch', ' world']
  print(ownResult);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  rich_string_parser: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:rich_string_parser/rich_string_parser.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
50
Learn more about scoring.

We analyzed this package on Dec 9, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.1
  • pana: 0.12.21

Health issues and suggestions

Document public APIs. (-0.30 points)

41 out of 42 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/src/parsers.dart.

Run dartfmt to format lib/src/parsers.dart.

Format lib/src/rich_string_parser_base.dart.

Run dartfmt to format lib/src/rich_string_parser_base.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.4.0 <3.0.0
Dev dependencies
pedantic ^1.7.0
test ^1.6.0