splitStringToParagraphs function Null safety

List<Paragraph> splitStringToParagraphs(
  1. String logicalString
)

Split the text into separate paragraphs.

A paragraph separator is kept with the previous paragraph. Within each paragraph, apply all the other rules of this algorithm.

3.3.1.P1.

Implementation

List<Paragraph> splitStringToParagraphs(String logicalString) {
  List<Paragraph> ret = [];

  var sb = <int>[];
  for (var i = 0; i < logicalString.length; ++i) {
    final c = logicalString.codeUnits[i];
    final cType = _getBidiCharacterType(c);
    if (cType == _BidiCharacterType.B) {
      final p = Paragraph._(sb, c);
      ret.add(p);
      sb = [];
    } else {
      sb.add(c);
    }
  }
  if (sb.isNotEmpty) // string ended without a paragraph separator
  {
    ret.add(Paragraph._(sb, _BidiChars.NotAChar));
  }
  return ret;
}