private void ResolveNeutralTypes(int start, int limit, sbyte level, sbyte sor, sbyte eor)
{
for (int i = start; i < limit; ++i) {
sbyte t = resultTypes[i];
if (t == WS || t == ON || t == B || t == S) {
// find bounds of run of neutrals
int runstart = i;
int runlimit = FindRunLimit(runstart, limit, new sbyte[] {B, S, WS, ON});
// determine effective types at ends of run
sbyte leadingType;
sbyte trailingType;
if (runstart == start) {
leadingType = sor;
} else {
leadingType = resultTypes[runstart - 1];
if (leadingType == L || leadingType == R) {
// found the strong type
} else if (leadingType == AN) {
leadingType = R;
} else if (leadingType == EN) {
// Since EN's with previous strong L types have been changed
// to L in W7, the leadingType must be R.
leadingType = R;
}
}
if (runlimit == limit) {
trailingType = eor;
} else {
trailingType = resultTypes[runlimit];
if (trailingType == L || trailingType == R) {
// found the strong type
} else if (trailingType == AN) {
trailingType = R;
} else if (trailingType == EN) {
trailingType = R;
}
}
sbyte resolvedType;
if (leadingType == trailingType) {
// Rule N1.
resolvedType = leadingType;
} else {
// Rule N2.
// Notice the embedding level of the run is used, not
// the paragraph embedding level.
resolvedType = TypeForLevel(level);
}
SetTypes(runstart, runlimit, resolvedType);
// skip over run of (former) neutrals
i = runlimit;
}
}
}