Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 541 → Rev 542

/trunk/src/org/tela_botanica/client/util/Pattern.java
New file
0,0 → 1,31
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();
}
}