package server; import java.util.BitSet; import java.util.HashMap; import structures.ByteBuilder; public class PercentEncoding { public static boolean containsSpecialSymbol(String s){ if(s==null){return false;} for(int i=0, max=s.length(); i=s.length()){return -1;} assert(s.charAt(start)=='%'); int sum=0; for(int i=start+1; i<=start+2; i++){ sum=sum<<4; final char c=s.charAt(i); if(c>='0' && c<='9'){ sum=sum+(c-'0'); }else if(c>='A' && c<'F'){ sum=sum+(10+c-'A'); }else{ return -1; } } return sum; } public static String codeToSymbol(String s){ int idx=s.indexOf('%'); if(idx<0){return s;} ByteBuilder bb=new ByteBuilder(s.length()); for(int i=0; i makeCodeToSymbolMap() { HashMap map=new HashMap(129); assert(reservedSymbol.length==reservedCode.length); assert(commonSymbol.length==commonCode.length); for(int i=0; i makeSymbolToCodeMap() { HashMap map=new HashMap(257); assert(reservedSymbol.length==reservedCode.length); assert(commonSymbol.length==commonCode.length); for(int i=0; i", "\\", "|", }; public static final String[] commonCode=new String[] { "%0A", "%20", "%22", "%25", "%3C", "%3E", "%5C", "%7C" }; private static final BitSet isSpecial=makeBitSet(reservedSymbol, commonSymbol); private static final BitSet isCommon=makeBitSet(commonSymbol); // public static final HashMap codeToSymbolMap=makeCodeToSymbolMap(); // public static final HashMap symbolToCodeMap=makeSymbolToCodeMap(); public static final String[] symbolToCodeArray=makeSymbolToCodeArray(); /** Don't print caught exceptions */ public static boolean suppressErrors=false; }