Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernd Hufmann2014-12-15 18:48:13 +0000
committerBernd Hufmann2014-12-16 13:35:30 +0000
commit7f8b6611ead970c83c8cde5b5d00caa05eea6127 (patch)
treed8aaeb0301a1ff81e3b9c23e29eda4ec4da4b68a /lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf
parentb149aa0314446ff9ca628eb6373d6ed03ef84219 (diff)
downloadorg.eclipse.linuxtools-7f8b6611ead970c83c8cde5b5d00caa05eea6127.tar.gz
org.eclipse.linuxtools-7f8b6611ead970c83c8cde5b5d00caa05eea6127.tar.xz
org.eclipse.linuxtools-7f8b6611ead970c83c8cde5b5d00caa05eea6127.zip
tmf: Add utility to support '\' and ':' for path manipulations
Change-Id: I588114891f1c59849134bf995b05461b935d462e Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com> Reviewed-on: https://git.eclipse.org/r/38279 Tested-by: Hudson CI Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com> Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com> Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Diffstat (limited to 'lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf')
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceCoreUtils.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceCoreUtils.java b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceCoreUtils.java
index 637e9b7d73..4747385b2b 100644
--- a/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceCoreUtils.java
+++ b/lttng/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/project/model/TmfTraceCoreUtils.java
@@ -14,6 +14,7 @@ package org.eclipse.linuxtools.tmf.core.project.model;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
/**
* Utility class for common tmf.core functionalities
@@ -22,9 +23,14 @@ import org.eclipse.core.resources.ResourcesPlugin;
*/
public class TmfTraceCoreUtils {
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
private static final boolean IS_WINDOWS = System.getProperty("os.name").contains("Windows") ? true : false; //$NON-NLS-1$ //$NON-NLS-2$
private static final String INVALID_RESOURCE_CHARACTERS_WIN = "[\\\\/:*?\\\"<>]|\\.$"; //$NON-NLS-1$
private static final String INVALID_RESOURCE_CHARACTERS_OTHER = "[/\0]"; //$NON-NLS-1$
+ private static final char BACKSLASH_PUA = 0xF000 + '\\';
+ private static final char COLON_PUA = 0xF000 + ':';
/**
* Validates whether the given input file or folder string is a valid
@@ -50,4 +56,29 @@ public class TmfTraceCoreUtils {
}
return output;
}
+
+ /**
+ * Creates a new safe path, replacing any invalid Windows file name
+ * characters '\' and ':' with characters in the Unicode Private Use Area.
+ *
+ * @param path
+ * a string path
+ * @return a safe path
+ */
+ public static Path newSafePath(String path) {
+ return new Path(path.replace('\\', BACKSLASH_PUA).replace(':', COLON_PUA));
+ }
+
+ /**
+ * Returns the string representation of a safe path, replacing characters
+ * in the Unicode Private Use Area back to their original value.
+ *
+ * @param path
+ * a safe path string
+ * @return a string representation of this path
+ */
+ public static String safePathToString(String path) {
+ return path.replace(BACKSLASH_PUA, '\\').replace(COLON_PUA, ':');
+ }
+
}

Back to the top