mapNormalizedSpan method
Maps normalized UTF-16 [start, end) to its exact original source span.
A non-empty span that includes a normalized surrogate code unit maps to the complete source scalar. Removed controls and marks between selected output characters are included in the returned span.
Implementation
ReferenceInputSpan mapNormalizedSpan(int start, int end) {
RangeError.checkValueInInterval(
start,
0,
normalizedText.length,
'start',
);
RangeError.checkValueInInterval(end, 0, normalizedText.length, 'end');
if (end < start) {
throw ArgumentError.value(end, 'end', 'must not be less than start');
}
if (start < end) {
return ReferenceInputSpan(
sourceSpans[start].start,
sourceSpans[end - 1].end,
);
}
if (sourceSpans.isEmpty) {
// The only normalized span is empty. When normalization removed the
// complete input, preserving that source extent is more useful than
// silently losing it (and makes full-input mapping lossless).
return ReferenceInputSpan(0, originalText.length);
}
if (start == 0) {
final offset = sourceSpans.first.start;
return ReferenceInputSpan(offset, offset);
}
if (start == sourceSpans.length) {
final offset = sourceSpans.last.end;
return ReferenceInputSpan(offset, offset);
}
final offset = sourceSpans[start].start;
return ReferenceInputSpan(offset, offset);
}