OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 28 | Rev 73 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28 Rev 61
Line 260... Line 260...
260
        result.append(lastString.toString().trim());
260
        result.append(lastString.toString().trim());
261
 
261
 
262
        return result.toString();
262
        return result.toString();
263
    }
263
    }
264
 
264
 
265
    static private final Pattern quotePatrn = Pattern.compile("([\\\\]*)\"");
265
    static private final Pattern quotePatrn = Pattern.compile("\"", Pattern.LITERAL);
266
    static private final Pattern endSlashPatrn = Pattern.compile("([\\\\]*)\\z");
266
    static private final Pattern slashPatrn = Pattern.compile("(\\\\+)");
267
 
267
 
268
    static public String doubleQuote(String s) {
268
    static public String doubleQuote(String s) {
-
 
269
        // http://developer.apple.com/library/mac/#documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-SW6
-
 
270
        // http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.10.5
-
 
271
        // https://developer.mozilla.org/en/JavaScript/Guide/Values%2C_Variables%2C_and_Literals#Escaping_characters
269
        if (s.length() > 0) {
272
        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
            s = slashPatrn.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");
274
            s = quotePatrn.matcher(s).replaceAll("\\\\\"");
276
        }
275
        }
277
        return '"' + s + '"';
276
        return '"' + s + '"';
278
    }
277
    }
279
 
278
 
280
    public static final class Escaper {
279
    public static final class Escaper {