Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1a66ba2c0c656f0816b4455ae3384e033ee263a5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package org.eclipse.jpt.jpadiagrameditor.ui.tests.internal.util;

public class URLEscaper {
	private static final String specialChars = " <>#%{}|^~[]`;?@=&$";
	private static final String escapeCodes  = "%20%3C%3E%23%25%7B%7D%7C%5E%7E%5B%5D%60%3B%3F%40%3D%26%24";
	
	public static String escape(String s) {
		if (s == null)
			return null;
		StringBuffer res = new StringBuffer("");
		for (int i = 0; i < s.length(); i++) {
			char ch = s.charAt(i);
			int ind = specialChars.indexOf(ch);
			res.append(((ind >= 0) ? escapeCodes.substring(ind * 3, ind * 3 + 3) : ch));   
		}
		return res.toString();
	}
}

Back to the top