Author: ggregory
Date: Tue Jul 28 06:57:15 2009
New Revision: 798420

URL: http://svn.apache.org/viewvc?rev=798420&view=rev
Log:
Use constants instead of literals.

Modified:
    
commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java

Modified: 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java
URL: 
http://svn.apache.org/viewvc/commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java?rev=798420&r1=798419&r2=798420&view=diff
==============================================================================
--- 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java
 (original)
+++ 
commons/proper/codec/trunk/src/java/org/apache/commons/codec/net/RFC1522Codec.java
 Tue Jul 28 06:57:15 2009
@@ -47,6 +47,21 @@
 abstract class RFC1522Codec {
     
     /**
+     * Separator.
+     */
+    protected static final char SEP = '?';
+
+    /**
+     * Prefix
+     */
+    protected static final String POSTFIX = "?=";
+
+    /**
+     * Postfix
+     */
+    protected static final String PREFIX = "=?";
+
+    /**
      * Applies an RFC 1522 compliant encoding scheme to the given string of 
text with the 
      * given charset. This method constructs the "encoded-word" header common 
to all the 
      * RFC 1522 codecs and then invokes {...@link #doEncoding(byte [])} method 
of a concrete 
@@ -70,14 +85,14 @@
             return null;
         }
         StringBuffer buffer = new StringBuffer();
-        buffer.append("=?"); 
-        buffer.append(charset); 
-        buffer.append('?'); 
-        buffer.append(getEncoding()); 
-        buffer.append('?');
+        buffer.append(PREFIX); 
+        buffer.append(charset);
+        buffer.append(SEP);
+        buffer.append(getEncoding());
+        buffer.append(SEP);
         byte [] rawdata = doEncoding(text.getBytes(charset)); 
         buffer.append(StringUtils.newStringUsAscii(rawdata));
-        buffer.append("?="); 
+        buffer.append(POSTFIX); 
         return buffer.toString();
     }
     
@@ -100,12 +115,12 @@
         if (text == null) {
             return null;
         }
-        if ((!text.startsWith("=?")) || (!text.endsWith("?="))) {
+        if ((!text.startsWith(PREFIX)) || (!text.endsWith(POSTFIX))) {
             throw new DecoderException("RFC 1522 violation: malformed encoded 
content");
         }
         int termnator = text.length() - 2;
         int from = 2;
-        int to = text.indexOf("?", from);
+        int to = text.indexOf(SEP, from);
         if ((to == -1) || (to == termnator)) {
             throw new DecoderException("RFC 1522 violation: charset token not 
found");
         }
@@ -114,7 +129,7 @@
             throw new DecoderException("RFC 1522 violation: charset not 
specified");
         }
         from = to + 1;
-        to = text.indexOf("?", from);
+        to = text.indexOf(SEP, from);
         if ((to == -1) || (to == termnator)) {
             throw new DecoderException("RFC 1522 violation: encoding token not 
found");
         }
@@ -124,7 +139,7 @@
                 encoding + " encoded content");
         }
         from = to + 1;
-        to = text.indexOf("?", from);
+        to = text.indexOf(SEP, from);
         byte[] data = StringUtils.getBytesUsAscii(text.substring(from, to));
         data = doDecoding(data); 
         return new String(data, charset);


Reply via email to