| Code with Finding: |
class BidiOrder {
/**
* Return levels array breaking lines at offsets in linebreaks. <br>
* Rule L1.
* <p>
* The returned levels array contains the resolved level for each
* bidi code passed to the constructor.
* <p>
* The linebreaks array must include at least one value.
* The values must be in strictly increasing order (no duplicates)
* between 1 and the length of the text, inclusive. The last value
* must be the length of the text.
*
* @param linebreaks the offsets at which to break the paragraph
* @return the resolved levels of the text
*/
public byte[] getLevels(int[] linebreaks) {
// Note that since the previous processing has removed all
// P, S, and WS values from resultTypes, the values referred to
// in these rules are the initial types, before any processing
// has been applied (including processing of overrides).
//
// This example implementation has reinserted explicit format codes
// and BN, in order that the levels array correspond to the
// initial text. Their final placement is not normative.
// These codes are treated like WS in this implementation,
// so they don't interrupt sequences of WS.
validateLineBreaks(linebreaks, textLength);
byte[] result = (byte[])resultLevels.clone(); // will be returned to caller
// don't worry about linebreaks since if there is a break within
// a series of WS values preceding S, the linebreak itself
// causes the reset.
for (int i = 0; i < result.length; ++i) {
byte t = initialTypes[i];
if (t == B || t == S) {
// Rule L1, clauses one and two.
result[i] = paragraphEmbeddingLevel;
// Rule L1, clause three.
for (int j = i - 1; j >= 0; --j) {
if (isWhitespace(initialTypes[j])) { // including format codes
result[j] = paragraphEmbeddingLevel;
} else {
break;
}
}
}
}
// Rule L1, clause four.
int start = 0;
for (int i = 0; i < linebreaks.length; ++i) {
int limit = linebreaks[i];
for (int j = limit - 1; j >= start; --j) {
if (isWhitespace(initialTypes[j])) { // including format codes
result[j] = paragraphEmbeddingLevel;
} else {
break;
}
}
start = limit;
}
return result;
}
}
|