Normalization.decompose constructor

Normalization.decompose(
  1. List<int> characters
)

Calculates the internal decomposition of the input text.

Implementation

factory Normalization.decompose(List<int> characters) {
  final List<int> text = [];
  final List<int> lengths = [];

  var hasPersian = false;
  var hasNSMs = false;

  for (int i = 0; i < characters.length; ++i) {
    final ct = getCharacterType(characters[i]);
    hasPersian |= ((ct == CharacterType.al) || (ct == CharacterType.an));
    hasNSMs |= (ct == CharacterType.nonspacingMark);

    final buffer = <int>[];
    _getRecursiveDecomposition(false, characters[i], buffer);
    lengths.add(1 - buffer.length);
    // add all of the characters in the decomposition.
    // (may be just the original character, if there was
    // no decomposition mapping)

    for (int j = 0; j < buffer.length; ++j) {
      final character = buffer[j];
      final chClass = _getCanonicalClass(character);
      int k = text.length; // insertion point
      if (chClass != _CanonicalClass.notReordered) {
        // bubble-sort combining marks as necessary
        int ch2;
        for (; k > 0; --k) {
          ch2 = text[k - 1];
          if (_getCanonicalClass(ch2).value <= chClass.value) break;
        }
      }

      text.insert(k, character);
    }
  }

  return Normalization._(text, lengths, hasPersian, hasNSMs);
}