8bdba0b861bcd857a8079791a4bd40ae3219ab6b
[phpeclipse.git] /
1 package net.sourceforge.phpeclipse.xdebug.core;
2
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
5
6 import org.w3c.dom.NamedNodeMap;
7 import org.w3c.dom.Node;
8
9 public class PHPDebugUtils {
10         public static String getAttributeValue(Node CurrentNode,
11                         String AttributeName) {
12                 String strValue = "";
13                 if (CurrentNode.hasAttributes()) {
14                         NamedNodeMap listAttribute = CurrentNode.getAttributes();
15                         Node attribute = listAttribute.getNamedItem(AttributeName);
16                         if (attribute != null)
17                                 strValue = attribute.getNodeValue();
18                 }
19                 return strValue;
20         }
21
22         public static String escapeString(String string) {
23                 StringBuffer escString = new StringBuffer();
24                 Pattern pattern = Pattern.compile("[a-zA-Z0-9\\._-]");
25                 Matcher matcher;
26                 for (int i = 0; i < string.length(); i++) {
27                         char c = string.charAt(i);
28                         matcher = pattern.matcher("" + c);
29                         if (matcher.find())
30                                 escString.append(c);
31                         else {
32                                 int hexval = (byte) c;
33                                 escString.append("%"
34                                                 + Integer.toHexString(hexval).toUpperCase());
35
36                         }
37                 }
38                 return escString.toString();
39         }
40
41         public static String unescapeString(String escString) {
42                 StringBuffer string = new StringBuffer();
43                 if (escString.indexOf('%') == -1)
44                         return escString;
45                 String[] s = escString.split("%");
46                 string.append(s[0]);
47                 for (int i = 1; i < s.length; i++) {
48                         int c = Integer.parseInt(s[i].substring(0, 2), 16);
49                         string.append((char) c);
50                         if (s[i].length() > 2)
51                                 string.append(s[i].substring(2));
52
53                 }
54                 return string.toString();
55
56         }
57
58 }