Subversion Repositories eFlore/Applications.coel

Rev

Rev 728 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
542 jp_milcent 1
package org.tela_botanica.client.util;
2
 
3
public class Pattern {
4
 
5
	/**
6
	 * Méthode similaire à la méthode : java.util.Pattern.quote().
7
	 * java.util.Pattern n'est pas implémenté par GWT.
8
	 *
9
	 * @link http://java.developpez.com/faq/java/?page=langage_chaine
10
	 * @param s
11
	 * @return
12
	 */
13
	public static String quote(String s) {
14
		int slashEIndex = s.indexOf("\\E");
15
		if (slashEIndex == -1)
16
			return "\\Q" + s + "\\E";
17
 
18
		StringBuffer sb = new StringBuffer(s.length() * 2);
19
		sb.append("\\Q");
20
		slashEIndex = 0;
21
		int current = 0;
22
		while ((slashEIndex = s.indexOf("\\E", current)) != -1) {
23
			sb.append(s.substring(current, slashEIndex));
24
			current = slashEIndex + 2;
25
			sb.append("\\E\\\\E\\Q");
26
		}
27
		sb.append(s.substring(current, s.length()));
28
		sb.append("\\E");
29
		return sb.toString();
30
	}
31
}