shouldBreak function
Implementation
int shouldBreak(int start, List<int> mid, int end) {
final all = [start];
all.addAll(mid);
all.addAll([end]);
final previous = all[all.length - 2];
final next = end;
final eModifierIndex = all.lastIndexOf(E_Modifier);
if (eModifierIndex > 1 &&
all.sublist(1, eModifierIndex).every((c) => c == Extend) &&
![Extend, E_Base, E_Base_GAZ].contains(start)) {
return Break;
}
var rIIndex = all.lastIndexOf(Regional_Indicator);
if (rIIndex > 0 &&
all.sublist(1, rIIndex).every((c) => c == Regional_Indicator) &&
![Prepend, Regional_Indicator].contains(previous)) {
if (all.where((c) => c == Regional_Indicator).length % 2 == 1) {
return BreakLastRegional;
} else {
return BreakPenultimateRegional;
}
}
if (previous == CR && next == LF) {
return NotBreak;
} else if (previous == Control || previous == CR || previous == LF) {
if (next == E_Modifier && mid.every((c) => c == Extend)) {
return Break;
} else {
return BreakStart;
}
} else if (next == Control || next == CR || next == LF) {
return BreakStart;
} else if (previous == L &&
(next == L || next == V || next == LV || next == LVT)) {
return NotBreak;
} else if ((previous == LV || previous == V) && (next == V || next == T)) {
return NotBreak;
} else if ((previous == LVT || previous == T) && next == T) {
return NotBreak;
} else if (next == Extend || next == ZWJ) {
return NotBreak;
} else if (next == SpacingMark) {
return NotBreak;
} else if (previous == Prepend) {
return NotBreak;
}
final previousNonExtendIndex =
all.contains(Extend) ? all.lastIndexOf(Extend) - 1 : all.length - 2;
if (previousNonExtendIndex != -1 &&
[E_Base, E_Base_GAZ].contains(all[previousNonExtendIndex]) &&
all.length > previousNonExtendIndex + 1 &&
sliceFromEnd(all, previousNonExtendIndex + 1).every((c) => c == Extend) &&
next == E_Modifier) {
return NotBreak;
}
if (previous == ZWJ && [Glue_After_Zwj, E_Base_GAZ].contains(next)) {
return NotBreak;
}
if (mid.contains(Regional_Indicator)) {
return Break;
}
if (previous == Regional_Indicator && next == Regional_Indicator) {
return NotBreak;
}
return BreakStart;
}