Tabs -> 8 spaces
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 20 Sep 2009 18:28:22 +0000 (18:28 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 20 Sep 2009 18:28:22 +0000 (18:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@817072 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/buf/UEncoder.java

index 8108a4c..b01d455 100644 (file)
@@ -47,15 +47,15 @@ public final class UEncoder {
     private static final int debug=0;
     
     public UEncoder() {
-       initSafeChars();
+        initSafeChars();
     }
 
     public void setEncoding( String s ) {
-       encoding=s;
+        encoding=s;
     }
 
     public void addSafeCharacter( char c ) {
-       safeChars.set( c );
+        safeChars.set( c );
     }
 
 
@@ -66,58 +66,56 @@ public final class UEncoder {
      * @throws IOException If an I/O error occurs
      */
     public void urlEncode( Writer buf, String s )
-       throws IOException
-    {
-       if( c2b==null ) {
-           bb=new ByteChunk(16); // small enough.
-           c2b=new C2BConverter( bb, encoding );
-       }
+            throws IOException {
+        if( c2b==null ) {
+            bb=new ByteChunk(16); // small enough.
+            c2b=new C2BConverter( bb, encoding );
+        }
 
-       for (int i = 0; i < s.length(); i++) {
-           int c = s.charAt(i);
-           if( safeChars.get( c ) ) {
-               if( debug > 0 ) log("Safe: " + (char)c);
-               buf.write((char)c);
-           } else {
-               if( debug > 0 ) log("Unsafe:  " + (char)c);
-               c2b.convert( (char)c );
-               
-               // "surrogate" - UTF is _not_ 16 bit, but 21 !!!!
-               // ( while UCS is 31 ). Amazing...
-               if (c >= 0xD800 && c <= 0xDBFF) {
-                   if ( (i+1) < s.length()) {
-                       int d = s.charAt(i+1);
-                       if (d >= 0xDC00 && d <= 0xDFFF) {
-                           if( debug > 0 ) log("Unsafe:  " + c);
-                           c2b.convert( (char)d);
-                           i++;
-                       }
-                   }
-               }
+        for (int i = 0; i < s.length(); i++) {
+            int c = s.charAt(i);
+            if( safeChars.get( c ) ) {
+                if( debug > 0 ) log("Safe: " + (char)c);
+                buf.write((char)c);
+            } else {
+                if( debug > 0 ) log("Unsafe:  " + (char)c);
+                c2b.convert( (char)c );
+                
+                // "surrogate" - UTF is _not_ 16 bit, but 21 !!!!
+                // ( while UCS is 31 ). Amazing...
+                if (c >= 0xD800 && c <= 0xDBFF) {
+                    if ( (i+1) < s.length()) {
+                        int d = s.charAt(i+1);
+                        if (d >= 0xDC00 && d <= 0xDFFF) {
+                            if( debug > 0 ) log("Unsafe:  " + c);
+                            c2b.convert( (char)d);
+                            i++;
+                        }
+                    }
+                }
 
-               c2b.flushBuffer();
-               
-               urlEncode( buf, bb.getBuffer(), bb.getOffset(),
-                          bb.getLength() );
-               bb.recycle();
-           }
-       }
+                c2b.flushBuffer();
+                
+                urlEncode( buf, bb.getBuffer(), bb.getOffset(),
+                           bb.getLength() );
+                bb.recycle();
+            }
+        }
     }
 
     /**
      */
     public void urlEncode( Writer buf, byte bytes[], int off, int len)
-       throws IOException
-    {
-       for( int j=off; j< len; j++ ) {
-           buf.write( '%' );
-           char ch = Character.forDigit((bytes[j] >> 4) & 0xF, 16);
-           if( debug > 0 ) log("Encode:  " + ch);
-           buf.write(ch);
-           ch = Character.forDigit(bytes[j] & 0xF, 16);
-           if( debug > 0 ) log("Encode:  " + ch);
-           buf.write(ch);
-       }
+            throws IOException {
+        for( int j=off; j< len; j++ ) {
+            buf.write( '%' );
+            char ch = Character.forDigit((bytes[j] >> 4) & 0xF, 16);
+            if( debug > 0 ) log("Encode:  " + ch);
+            buf.write(ch);
+            ch = Character.forDigit(bytes[j] & 0xF, 16);
+            if( debug > 0 ) log("Encode:  " + ch);
+            buf.write(ch);
+        }
     }
     
     /**
@@ -126,48 +124,48 @@ public final class UEncoder {
      * ignores it.
      */
     public String encodeURL(String uri) {
-       String outUri=null;
-       try {
-           // XXX optimize - recycle, etc
-           CharArrayWriter out = new CharArrayWriter();
-           urlEncode(out, uri);
-           outUri=out.toString();
-       } catch (IOException iex) {
-       }
-       return outUri;
+        String outUri=null;
+        try {
+            // XXX optimize - recycle, etc
+            CharArrayWriter out = new CharArrayWriter();
+            urlEncode(out, uri);
+            outUri=out.toString();
+        } catch (IOException iex) {
+        }
+        return outUri;
     }
     
 
     // -------------------- Internal implementation --------------------
     
     private void initSafeChars() {
-       safeChars=new BitSet(128);
-       int i;
-       for (i = 'a'; i <= 'z'; i++) {
-           safeChars.set(i);
-       }
-       for (i = 'A'; i <= 'Z'; i++) {
-           safeChars.set(i);
-       }
-       for (i = '0'; i <= '9'; i++) {
-           safeChars.set(i);
-       }
-       //safe
-       safeChars.set('$');
-       safeChars.set('-');
-       safeChars.set('_');
-       safeChars.set('.');
+        safeChars=new BitSet(128);
+        int i;
+        for (i = 'a'; i <= 'z'; i++) {
+            safeChars.set(i);
+        }
+        for (i = 'A'; i <= 'Z'; i++) {
+            safeChars.set(i);
+        }
+        for (i = '0'; i <= '9'; i++) {
+            safeChars.set(i);
+        }
+        //safe
+        safeChars.set('$');
+        safeChars.set('-');
+        safeChars.set('_');
+        safeChars.set('.');
 
-       // Dangerous: someone may treat this as " "
-       // RFC1738 does allow it, it's not reserved
-       //    safeChars.set('+');
-       //extra
-       safeChars.set('!');
-       safeChars.set('*');
-       safeChars.set('\'');
-       safeChars.set('(');
-       safeChars.set(')');
-       safeChars.set(',');     
+        // Dangerous: someone may treat this as " "
+        // RFC1738 does allow it, it's not reserved
+        //    safeChars.set('+');
+        //extra
+        safeChars.set('!');
+        safeChars.set('*');
+        safeChars.set('\'');
+        safeChars.set('(');
+        safeChars.set(')');
+        safeChars.set(',');
     }
 
     private static void log( String s ) {