18,27 → 18,19 |
/** |
* Méthode similaire à la méthode : java.util.Pattern.quote(). |
* java.util.Pattern n'est pas implémenté par GWT. |
* Nous protégeons les caractères spéciaux. |
* |
* @link http://java.developpez.com/faq/java/?page=langage_chaine |
* @param s |
* @param chaine |
* @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"); |
public static String quote(String chaine) { |
chaine.replace("\\", "\\\\"); |
|
String[] caracteresSpeciaux = {".", "$", "[", "]", "(", ")", "{", "}", "^", "?", "*", "+", "-"}; |
for (int i = 0; i < caracteresSpeciaux.length; i++) { |
chaine = chaine.replace(caracteresSpeciaux[i], "\\"+caracteresSpeciaux[i]); |
} |
sb.append(s.substring(current, s.length())); |
sb.append("\\E"); |
return sb.toString(); |
return chaine; |
} |
} |