Revision 994 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/persistence/impl/FileTools.java

View differences:

FileTools.java
1 1
package org.gvsig.tools.persistence.impl;
2 2

  
3 3
import java.io.File;
4
import java.util.regex.Pattern;
4
import org.apache.commons.io.FilenameUtils;
5 5

  
6 6
public class FileTools {
7 7

  
......
25 25
		// "" token if the base ends in the path separator and is therefore
26 26
		// a directory. We require directory paths to end in the path
27 27
		// separator -- otherwise they are indistinguishable from files.
28
		String[] base = basePath.split(Pattern.quote(pathSeparator), -1);
29
		String[] target = targetPath.split(Pattern.quote(pathSeparator), 0);
28
		String[] base = basePath.split(Pattern_quote(pathSeparator), -1);
29
		String[] target = targetPath.split(Pattern_quote(pathSeparator), 0);
30 30

  
31 31
		// First get all the common elements. Store them as a string,
32 32
		// and also count how many of them there are.
......
98 98
        // "" token if the base ends in the path separator and is therefore
99 99
        // a directory. We require directory paths to end in the path
100 100
        // separator -- otherwise they are indistinguishable from files.
101
        String[] base = basePath.split(Pattern.quote(pathSeparator), -1);
102
        String[] target = targetPath.split(Pattern.quote(pathSeparator), 0);
101
        String[] base = basePath.split(Pattern_quote(pathSeparator), -1);
102
        String[] target = targetPath.split(Pattern_quote(pathSeparator), 0);
103 103
        /*
104 104
         * If first component is different then they are different
105 105
         * drives. In Unix-type file systems, the first for both
......
108 108
        return !target[0].equals(base[0]);
109 109
    }
110 110

  
111
    
112
    private static String Pattern_quote(String str) {
113
        int eInd = str.indexOf("\\E");
114
        if (eInd < 0) {
115
            // No need to handle backslashes.
116
            return "\\Q" + str + "\\E";
117
        }
118

  
119
        StringBuffer sb = new StringBuffer(str.length() + 16);
120
        sb.append("\\Q"); // start quote
121

  
122
        int pos = 0;
123
        do {
124
        // A backslash is quoted by another backslash;
125
            // 'E' is not needed to be quoted.
126
            sb.append(str.substring(pos, eInd))
127
                    .append("\\E" + "\\\\" + "E" + "\\Q");
128
            pos = eInd + 2;
129
        } while ((eInd = str.indexOf("\\E", pos)) >= 0);
130

  
131
        sb.append(str.substring(pos, str.length()))
132
                .append("\\E"); // end quote
133
        return sb.toString();
134
    }
135

  
111 136
}

Also available in: Unified diff