OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 25 | Rev 61 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25 Rev 28
Line 23... Line 23...
23
import java.util.HashSet;
23
import java.util.HashSet;
24
import java.util.LinkedHashMap;
24
import java.util.LinkedHashMap;
25
import java.util.List;
25
import java.util.List;
26
import java.util.Map;
26
import java.util.Map;
27
import java.util.Set;
27
import java.util.Set;
-
 
28
import java.util.regex.Pattern;
28
 
29
 
29
/**
30
/**
30
 * @author Sylvain CUAZ
31
 * @author Sylvain CUAZ
31
 */
32
 */
32
public class StringUtils {
33
public class StringUtils {
33
 
34
 
-
 
35
    // required encoding see
-
 
36
    // http://docs.oracle.com/javase/7/docs/technotes/guides/intl/encoding.doc.html
34
    private static final Charset UTF8 = Charset.forName("UTF8");
37
    public static final Charset UTF8 = Charset.forName("UTF8");
-
 
38
    public static final Charset UTF16 = Charset.forName("UTF-16");
-
 
39
    public static final Charset ASCII = Charset.forName("ASCII");
-
 
40
    public static final Charset ISO8859_1 = Charset.forName("ISO8859_1");
-
 
41
    public static final Charset Cp1252 = Charset.forName("Cp1252");
-
 
42
    public static final Charset Cp850 = Charset.forName("Cp850");
35
 
43
 
36
    /**
44
    /**
37
     * Retourne la chaine avec la première lettre en majuscule et le reste en minuscule.
45
     * Retourne la chaine avec la première lettre en majuscule et le reste en minuscule.
38
     * 
46
     * 
39
     * @param s la chaîne à transformer.
47
     * @param s la chaîne à transformer.
Line 252... Line 260...
252
        result.append(lastString.toString().trim());
260
        result.append(lastString.toString().trim());
253
 
261
 
254
        return result.toString();
262
        return result.toString();
255
    }
263
    }
256
 
264
 
-
 
265
    static private final Pattern quotePatrn = Pattern.compile("([\\\\]*)\"");
-
 
266
    static private final Pattern endSlashPatrn = Pattern.compile("([\\\\]*)\\z");
-
 
267
 
-
 
268
    static public String doubleQuote(String s) {
-
 
269
        if (s.length() > 0) {
-
 
270
            // replace '(\*)"' by '$1$1\"', e.g. '\quote " \"' by '\quote \" \\\"'
-
 
271
            // $1 needed so that the backslash we add isn't escaped itself by a preceding backslash
-
 
272
            s = quotePatrn.matcher(s).replaceAll("$1$1\\\\\"");
-
 
273
            // replace '(\*)\z' by '$1$1', e.g. 'foo\' by 'foo\\'
-
 
274
            // needed to not escape closing quote
-
 
275
            s = endSlashPatrn.matcher(s).replaceAll("$1$1");
-
 
276
        }
-
 
277
        return '"' + s + '"';
-
 
278
    }
-
 
279
 
257
    public static final class Escaper {
280
    public static final class Escaper {
258
 
281
 
259
        // eg '
282
        // eg '
260
        private final char esc;
283
        private final char esc;
261
 
284