You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2009/09/20 20:28:22 UTC

svn commit: r817072 - /tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java

Author: markt
Date: Sun Sep 20 18:28:22 2009
New Revision: 817072

URL: http://svn.apache.org/viewvc?rev=817072&view=rev
Log:
Tabs -> 8 spaces

Modified:
    tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java

Modified: tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java?rev=817072&r1=817071&r2=817072&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java (original)
+++ tomcat/trunk/java/org/apache/tomcat/util/buf/UEncoder.java Sun Sep 20 18:28:22 2009
@@ -47,15 +47,15 @@
     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 @@
      * @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 );
-	}
-
-	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();
-	    }
-	}
+            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++;
+                        }
+                    }
+                }
+
+                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 @@
      * 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('.');
-
-	// 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(',');	
+        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(',');
     }
 
     private static void log( String s ) {



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org