mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
avoiding toLowerCase() calls
This commit is contained in:
@@ -210,18 +210,14 @@ public class FileUtilRt {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getRelativePath(@NotNull String basePath,
|
||||
@NotNull String filePath,
|
||||
final char separator,
|
||||
final boolean caseSensitive) {
|
||||
public static String getRelativePath(@NotNull String basePath, @NotNull String filePath, final char separator, final boolean caseSensitive) {
|
||||
basePath = ensureEnds(basePath, separator);
|
||||
|
||||
String basePathToCompare = caseSensitive ? basePath : basePath.toLowerCase();
|
||||
String filePathToCompare = caseSensitive ? filePath : filePath.toLowerCase();
|
||||
if (basePathToCompare.equals(ensureEnds(filePathToCompare, separator))) return ".";
|
||||
if (basePath.equals(ensureEnds(filePath, separator))) return ".";
|
||||
int len = 0;
|
||||
int lastSeparatorIndex = 0; // need this for cases like this: base="/temp/abc/base" and file="/temp/ab"
|
||||
while (len < filePath.length() && len < basePath.length() && filePathToCompare.charAt(len) == basePathToCompare.charAt(len)) {
|
||||
final CharComparingStrategy charComparingStrategy = caseSensitive? CharComparingStrategy.IDENTITY : CharComparingStrategy.CASE_INSENSITIVE;
|
||||
while (len < filePath.length() && len < basePath.length() && charComparingStrategy.charsEqual(filePath.charAt(len), basePath.charAt(len))) {
|
||||
if (basePath.charAt(len) == separator) {
|
||||
lastSeparatorIndex = len;
|
||||
}
|
||||
@@ -798,4 +794,21 @@ public class FileUtilRt {
|
||||
return 2500 * KILOBYTE;
|
||||
}
|
||||
}
|
||||
|
||||
private interface CharComparingStrategy {
|
||||
CharComparingStrategy IDENTITY = new CharComparingStrategy() {
|
||||
@Override
|
||||
public boolean charsEqual(char ch1, char ch2) {
|
||||
return ch1 == ch2;
|
||||
}
|
||||
};
|
||||
CharComparingStrategy CASE_INSENSITIVE = new CharComparingStrategy() {
|
||||
@Override
|
||||
public boolean charsEqual(char ch1, char ch2) {
|
||||
return StringUtilRt.charsEqualIgnoreCase(ch1, ch2);
|
||||
}
|
||||
};
|
||||
|
||||
boolean charsEqual(char ch1, char ch2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user