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