Subversion Repositories eFlore/Applications.coel

Rev

Rev 744 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.util;

public class Pattern {

        /**
         * Méthode similaire à la méthode : java.util.Pattern.quote().
         * java.util.Pattern n'est pas implémenté par GWT.
         * 
         * @link http://java.developpez.com/faq/java/?page=langage_chaine
         * @param s
         * @return
         */
        public static String quote(String s) {
                int slashEIndex = s.indexOf("\\E");
                if (slashEIndex == -1)
                        return "\\Q" + s + "\\E";

                StringBuffer sb = new StringBuffer(s.length() * 2);
                sb.append("\\Q");
                slashEIndex = 0;
                int current = 0;
                while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
                        sb.append(s.substring(current, slashEIndex));
                        current = slashEIndex + 2;
                        sb.append("\\E\\\\E\\Q");
                }
                sb.append(s.substring(current, s.length()));
                sb.append("\\E");
                return sb.toString();
        }
}