Merge pull request #641 from ebraminio/patch-1

Use split limit
This commit is contained in:
Athou
2014-10-06 11:18:04 +02:00

View File

@@ -30,7 +30,7 @@ class EstimateDirection {
static boolean isRTL(String str) {
int rtlCount = 0;
int total = 0;
String[] tokens = WORD_SEPARATOR_RE.split(str);
String[] tokens = WORD_SEPARATOR_RE.split(str, 20); // limit splits to 20, usually enough
for (int i = 0; i < tokens.length; i++) {
String token = tokens[i];
if (startsWithRtl(token)) {
@@ -41,11 +41,6 @@ class EstimateDirection {
} else if (hasAnyLtr(token)) {
total++;
}
// only checking 20 first words is usually enough
if (i == 20) {
break;
}
}
return total == 0 ? false : ((float) rtlCount / total > RTL_DETECTION_THRESHOLD ? true : false);