From 30597f098738cb5b9f55232a26c128cedb8d50e4 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Tue, 31 Oct 2006 13:54:18 +0000 Subject: [PATCH] Normalize pathes without using replaceAll() --- .../services/clientserver/PathUtility.java | 96 +++++++++++-------- 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/PathUtility.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/PathUtility.java index 797c38f5803..0df933d5896 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/PathUtility.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/PathUtility.java @@ -11,8 +11,8 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * Martin Oberhuber (Wind River) - Fix for bug 161844 - regex matching backslashes - * + * Martin Oberhuber (Wind River) - Fix 161844 - regex matching backslashes + * Martin Oberhuber (Wind River) - Fix 162781 - normalize without replaceAll() ********************************************************************************/ package org.eclipse.rse.services.clientserver; @@ -35,26 +35,32 @@ public class PathUtility if (path.indexOf("\\\\") != -1) containsDoubleSlashes = true; //$NON-NLS-1$ if (path.endsWith("\\") || path.endsWith("/")) endsWithSlash = true; //$NON-NLS-1$ //$NON-NLS-2$ - boolean needsNormalizing = containsForwardSlash || containsDoubleSlashes || endsWithSlash; - if (!needsNormalizing) return path; - - if (containsForwardSlash) - { - path = path.replace('/', '\\'); - containsDoubleSlashes = (path.indexOf("\\\\") != -1); //$NON-NLS-1$ - } - - while (containsDoubleSlashes) - { - //TODO Improve performance by manually iterating over char array - //need to quote once for the string, then again for the regex - //Replace "\\" by "\": Regex matcher needs quoting twice in search, once in replacement - path = path.replaceAll("\\\\\\\\", "\\\\"); //$NON-NLS-1$ //$NON-NLS-2$ - containsDoubleSlashes = (path.indexOf("\\\\") != -1); //$NON-NLS-1$ - } - if (endsWithSlash) - { - if (!(path.length() == 3)) path = path.substring(0, path.length() - 1); + if (containsForwardSlash || containsDoubleSlashes) { + //Replace /->\, then replace \\->\ + StringBuffer buf = new StringBuffer(path.length()); + boolean foundBackslash=false; + for (int i=0; i/, then replace //->/ + StringBuffer buf = new StringBuffer(path.length()); + boolean foundSlash=false; + for (int i=0; i