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