summaryrefslogtreecommitdiff
path: root/platform/util/src/com/intellij/openapi/util
diff options
context:
space:
mode:
Diffstat (limited to 'platform/util/src/com/intellij/openapi/util')
-rw-r--r--platform/util/src/com/intellij/openapi/util/io/FileUtil.java9
-rw-r--r--platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java2
-rw-r--r--platform/util/src/com/intellij/openapi/util/text/StringUtil.java73
3 files changed, 79 insertions, 5 deletions
diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
index 0f95577cf2b5..cfcbe7967d35 100644
--- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java
@@ -1255,10 +1255,15 @@ public class FileUtil extends FileUtilRt {
}
@Contract("null -> null")
- public static String getLocationRelativeToUserHome(@Nullable final String path) {
+ public static String getLocationRelativeToUserHome(@Nullable String path) {
+ return getLocationRelativeToUserHome(path, true);
+ }
+
+ @Contract("null,_ -> null")
+ public static String getLocationRelativeToUserHome(@Nullable String path, boolean unixOnly) {
if (path == null) return null;
- if (SystemInfo.isUnix) {
+ if (SystemInfo.isUnix || !unixOnly) {
final File projectDir = new File(path);
final File userHomeDir = new File(SystemProperties.getUserHome());
if (isAncestor(userHomeDir, projectDir, true)) {
diff --git a/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java b/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java
index 3484d0625d37..586668af3864 100644
--- a/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java
+++ b/platform/util/src/com/intellij/openapi/util/io/win32/IdeaWin32.java
@@ -35,7 +35,7 @@ public class IdeaWin32 {
static {
IdeaWin32 instance = null;
- if (SystemInfo.isWin2kOrNewer) {
+ if (SystemInfo.isWin2kOrNewer && Boolean.parseBoolean(System.getProperty("idea.use.native.fs.for.win", "true"))) {
try {
UrlClassLoader.loadPlatformLibrary("IdeaWin32");
instance = new IdeaWin32();
diff --git a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
index 7ee904c1f344..bc37f673bb03 100644
--- a/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
+++ b/platform/util/src/com/intellij/openapi/util/text/StringUtil.java
@@ -923,6 +923,10 @@ public class StringUtil extends StringUtilRt {
}
}
+ public static String defaultIfEmpty(@Nullable String value, String defaultValue) {
+ return isEmpty(value) ? defaultValue : value;
+ }
+
@Contract("null -> false")
public static boolean isNotEmpty(@Nullable String s) {
return s != null && !s.isEmpty();
@@ -2513,10 +2517,9 @@ public class StringUtil extends StringUtilRt {
public static String shortenTextWithEllipsis(@NotNull final String text,
final int maxLength,
final int suffixLength,
- boolean useEllipsisSymbol) {
+ @NotNull String symbol) {
final int textLength = text.length();
if (textLength > maxLength) {
- String symbol = useEllipsisSymbol ? "\u2026" : "...";
final int prefixLength = maxLength - suffixLength - symbol.length();
assert prefixLength > 0;
return text.substring(0, prefixLength) + symbol + text.substring(textLength - suffixLength);
@@ -2527,6 +2530,15 @@ public class StringUtil extends StringUtilRt {
}
@NotNull
+ public static String shortenTextWithEllipsis(@NotNull final String text,
+ final int maxLength,
+ final int suffixLength,
+ boolean useEllipsisSymbol) {
+ String symbol = useEllipsisSymbol ? "\u2026" : "...";
+ return shortenTextWithEllipsis(text, maxLength, suffixLength, symbol);
+ }
+
+ @NotNull
public static String shortenPathWithEllipsis(@NotNull final String path, final int maxLength, boolean useEllipsisSymbol) {
return shortenTextWithEllipsis(path, maxLength, (int)(maxLength * 0.7), useEllipsisSymbol);
}
@@ -2650,6 +2662,63 @@ public class StringUtil extends StringUtilRt {
return s.startsWith(smallPart.toLowerCase()) && bigPart.toLowerCase().startsWith(s);
}
+ public static String getShortened(String s, int maxWidth) {
+ int length = s.length();
+ if (isEmpty(s) || length <= maxWidth) return s;
+ ArrayList<String> words = new ArrayList<String>();
+
+ StringBuilder builder = new StringBuilder();
+ for (int i = 0; i < length; i++) {
+ char ch = s.charAt(i);
+
+ if (i == length - 1) {
+ builder.append(ch);
+ words.add(builder.toString());
+ builder.delete(0, builder.length());
+ continue;
+ }
+
+ if (i > 0 && (ch == '/' || ch == '\\' || ch == '.' || Character.isUpperCase(ch))) {
+ words.add(builder.toString());
+ builder.delete(0, builder.length());
+ }
+ builder.append(ch);
+ }
+ for (int i = 0; i < words.size(); i++) {
+ String word = words.get(i);
+ if (i < words.size() - 1 && word.length() == 1) {
+ words.remove(i);
+ words.set(i, word + words.get(i));
+ }
+ }
+
+ int removedLength = 0;
+
+ String toPaste = "...";
+ int index;
+ while (true) {
+ index = Math.max(0, (words.size() - 1) / 2);
+ String aWord = words.get(index);
+ words.remove(index);
+ int toCut = length - removedLength - maxWidth + 3;
+ if (words.size() < 2 || (toCut < aWord.length() - 2 && removedLength == 0)) {
+ int pos = (aWord.length() - toCut) / 2;
+ toPaste = aWord.substring(0, pos) + "..." + aWord.substring(pos+toCut);
+ break;
+ }
+ removedLength += aWord.length();
+ if (length - removedLength <= maxWidth - 3) {
+ break;
+ }
+ }
+ for (int i = 0; i < words.size(); i++) {
+ String word = words.get(i);
+ if (i == index || words.size() == 1) builder.append(toPaste);
+ builder.append(word);
+ }
+ return builder.toString().replaceAll("\\.{4,}", "...");
+ }
+
/**
* Expirable CharSequence. Very useful to control external library execution time,
* i.e. when java.util.regex.Pattern match goes out of control.