text 0.1.0

  • README.md
  • Example
  • Installing
  • Versions
  • 47

text

The package 'text' allows to get detailed information about the text such as the number of lines, lines at positions, characters at locations, locations at positions, positions at locations, and vice versa.

It is much faster than you could possibly imagine, thanks to the sparse lists.

import "package:text/text.dart";

void main() {
  var text = new Text(string);
  var position = text.length ~/ 2;
  // Get the line by the character position
  var line = text.lineAt(position);
  print("#${line.number}: ${toStr(line.characters)}");

  // Get the location by the character position
  var location = text.locationAt(position);
  print("pos: $position => loc: ${location.line}:${location.column}");

  // Get the character position by the location
  position = text.position(location);
  print("loc: ${location.line}:${location.column} => pos: $position");

  // Get the line by index (line.number - 1)
  var line2 = text.line(line.number - 1);
  print("#${line.number} = #${line2.number}");

  // Search the Unicode character and display it location and string
  var char = 65504; // ¢
  position = text.characters.indexOf(char);
  location = text.locationAt(position);
  line = text.lineAt(position);
  print("${toStr([char])} found at pos: $position");
  print("${toStr([char])} found at loc: ${location.line}:${location.column}");
  print("${toStr([char])} found in line: ${toStr(line.characters)}");
}

String toStr(List<int> characters) => new String.fromCharCodes(characters);

String string = '''
1. Line 1
2. Line 2
3. Line 3
4. Line 4
5. Line 5 ¢
''';

Output:

#3: 3. Line 3

pos: 26 => loc: 3:7
loc: 3:7 => pos: 26
#3 = #3
¢ found at pos: 50
¢ found at loc: 5:11
¢ found in line: 5. Line 5 ¢

example/example.dart

import "package:text/text.dart";

void main() {
  var text = new Text(string);
  var position = text.length ~/ 2;
  // Get the line by the character position
  var line = text.lineAt(position);
  print("#${line.number}: ${toStr(line.characters)}");

  // Get the location by the character position
  var location = text.locationAt(position);
  print("pos: $position => loc: ${location.line}:${location.column}");

  // Get the character position by the location
  position = text.position(location);
  print("loc: ${location.line}:${location.column} => pos: $position");

  // Get the line by index (line.number - 1)
  var line2 = text.line(line.number - 1);
  print("#${line.number} = #${line2.number}");

  // Search the Unicode character and display it location and string
  var char = 65504; // ¢
  position = text.characters.indexOf(char);
  location = text.locationAt(position);
  line = text.lineAt(position);
  print("${toStr([char])} found at pos: $position");
  print("${toStr([char])} found at loc: ${location.line}:${location.column}");
  print("${toStr([char])} found in line: ${toStr(line.characters)}");
}

String toStr(List<int> characters) => new String.fromCharCodes(characters);

String string = '''
1. Line 1
2. Line 2
3. Line 3
4. Line 4
5. Line 5 ¢
''';

Use this package as a library

1. Depend on it

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


dependencies:
  text: ^0.1.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

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

3. Import it

Now in your Dart code, you can use:


import 'package:text/text.dart';
  
Version Uploaded Documentation Archive
0.1.0 Aug 29, 2018 Go to the documentation of text 0.1.0 Download text 0.1.0 archive
0.0.7 Sep 25, 2014 Go to the documentation of text 0.0.7 Download text 0.0.7 archive
0.0.6 Sep 24, 2014 Go to the documentation of text 0.0.6 Download text 0.0.6 archive
0.0.4 Sep 17, 2014 Go to the documentation of text 0.0.4 Download text 0.0.4 archive
0.0.3 Sep 17, 2014 Go to the documentation of text 0.0.3 Download text 0.0.3 archive
0.0.2 Sep 17, 2014 Go to the documentation of text 0.0.2 Download text 0.0.2 archive
0.0.1 Sep 17, 2014 Go to the documentation of text 0.0.1 Download text 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
6
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
47
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:text/text.dart.

Health suggestions

Format lib/src/text.dart.

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

Maintenance issues and suggestions

Maintain CHANGELOG.md. (-20 points)

Changelog entries help clients to follow the progress in your code.

The description is too long. (-10 points)

Search engines will display only the first part of the description. Try to keep it under 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
lists ^0.0.23 0.0.23
Dev dependencies
test ^1.3.0