hyphenatorx 1.1.1 copy "hyphenatorx: ^1.1.1" to clipboard
hyphenatorx: ^1.1.1 copied to clipboard

Implementation of an hyphenation algorithm, based on TeX definitions.

Hyphenator #

Implementation of an hyphenation algorithm.

The tex patterns used in the algorithm can be found here.

The package seems to work fine for western languages, other languages have to be evaluated.

A live Flutter demo can be found here: https://xerik.github.io/hyphenatorx/.

Installation #

flutter pub add hyphenatorx

Usage #

Hyphenator instantiates a language specific configuration:

As a Dart object

Without synchronous loading. The data is compiled into your project. All 71 langauge files together have a size of 13.3 MB.

From JSON

With asynchronous loading. The data will be loaded as needed from the local assets folder. This option is less memory intensive.

Languages

Available languages are given by the enum Language.

Cache

Internally, hyphenated as well as non-hyphenated words are cached.

Asynchronous Instantiation #

Select the appropriate Language.language_XX value.

import 'package:hyphenatorx/hyphenatorx.dart';
import 'package:hyphenatorx/languages/language_en_us.dart';
import 'package:hyphenatorx/languages/languageconfig.dart';

final hyphernator = await Hyphenator.load(
    Language.language_en_us, 
    hyphenateSymbol: '_');

expect(
  hyphenator.hyphenate('subdivision subdivision'), 
  'sub_di_vi_sion sub_di_vi_sion');

expect(
  hyphenator.hyphenateWord('subdivision'),
  'sub_di_vi_sion');

expect(
  hyphenator.hyphenateWordToList('subdivision'),
  ['sub', 'di', 'vi', 'sion']);

Synchronous Instantiation #

Instatiate the appropriate Language_XX object.

import 'package:hyphenatorx/hyphenatorx.dart';
import 'package:hyphenatorx/languages/language_en_us.dart';
import 'package:hyphenatorx/languages/languageconfig.dart';

final LanguageConfig config = Language_en_us();

final hyphenator = Hyphenator(
  config,
  hyphenateSymbol: '_',
);

expect(
  hyphenator.hyphenate('subdivision subdivision'), 
  'sub_di_vi_sion sub_di_vi_sion');

expect(
  hyphenator.hyphenateWord('subdivision'),
  'sub_di_vi_sion');

expect(
  hyphenator.hyphenateWordToList('subdivision'),
  ['sub', 'di', 'vi', 'sion']);

Generate JSON and Dart files #

dart run ./tool/tex2dart.dart

The tool will delete assets and lib/languages before generating new files. It processes tex files located in tool\tex\.

Source #

This package is a copy and extension of hyphenator.

Possible performance improvement and general refactoring is TBD.

4
likes
0
pub points
83%
popularity

Publisher

verified publishernovelplotter.com

Implementation of an hyphenation algorithm, based on TeX definitions.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on hyphenatorx