mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: optimize isPunctuation() and isAlpha() checks
This commit is contained in:
@@ -17,7 +17,6 @@ package com.intellij.diff.comparison;
|
||||
|
||||
import com.intellij.diff.util.IntPair;
|
||||
import com.intellij.diff.util.Range;
|
||||
import gnu.trove.TIntHashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,23 +25,30 @@ import static com.intellij.openapi.util.text.StringUtil.isWhiteSpace;
|
||||
|
||||
@SuppressWarnings({"Duplicates", "unused", "TypeParameterExplicitlyExtendsObject"})
|
||||
public class TrimUtil {
|
||||
private static final String PUNCTUATION = "(){}[],./?`~!@#$%^&*-=+|\\;:'\"<>";
|
||||
private static final TIntHashSet PUNCTUATION_SET = new TIntHashSet();
|
||||
|
||||
static {
|
||||
for (char punctuation : PUNCTUATION.toCharArray()) {
|
||||
PUNCTUATION_SET.add(punctuation);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPunctuation(char c) {
|
||||
return PUNCTUATION_SET.contains(c);
|
||||
if (c == '_') return false;
|
||||
boolean isPunctuation = false;
|
||||
isPunctuation |= c >= 33 & c <= 47; // !"#$%&'()*+,-./
|
||||
isPunctuation |= c >= 58 & c <= 64; // :;<=>?@
|
||||
isPunctuation |= c >= 91 & c <= 96; // [\]^_`
|
||||
isPunctuation |= c >= 123 & c <= 126; // {|}~
|
||||
return isPunctuation;
|
||||
}
|
||||
|
||||
public static boolean isAlpha(char c) {
|
||||
return !isWhiteSpace(c) && !PUNCTUATION_SET.contains(c);
|
||||
return !isWhiteSpace(c) && !isPunctuation(c);
|
||||
}
|
||||
|
||||
//public static void main(String[] args) {
|
||||
// String PUNCTUATION = "(){}[],./?`~!@#$%^&*-=+|\\;:'\"<>";
|
||||
// for (char c = Character.MIN_VALUE; c < Character.MAX_VALUE; c++) {
|
||||
// if (StringUtil.containsChar(PUNCTUATION, c) != isPunctuation(c)) System.out.println("'" + c + "' - " + (int)c);
|
||||
// }
|
||||
// char c = Character.MAX_VALUE;
|
||||
// if (StringUtil.containsChar(PUNCTUATION, c) != isPunctuation(c)) System.out.println("'" + c + "' - " + (int)c);
|
||||
// System.out.println("Finish");
|
||||
//}
|
||||
|
||||
//
|
||||
// Trim
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user