@@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828 * Convert a web browser cookie specification to a JSONObject and back.
2929 * JSON and Cookies are both notations for name/value pairs.
3030 * @author JSON.org
31- * @version 2008-09-18
31+ * @version 2010-12-24
3232 */
3333public class Cookie {
3434
@@ -48,8 +48,8 @@ public static String escape(String string) {
4848 char c ;
4949 String s = string .trim ();
5050 StringBuffer sb = new StringBuffer ();
51- int len = s .length ();
52- for (int i = 0 ; i < len ; i += 1 ) {
51+ int length = s .length ();
52+ for (int i = 0 ; i < length ; i += 1 ) {
5353 c = s .charAt (i );
5454 if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';' ) {
5555 sb .append ('%' );
@@ -79,29 +79,29 @@ public static String escape(String string) {
7979 * @throws JSONException
8080 */
8181 public static JSONObject toJSONObject (String string ) throws JSONException {
82- String n ;
83- JSONObject o = new JSONObject ();
84- Object v ;
82+ String name ;
83+ JSONObject jo = new JSONObject ();
84+ Object value ;
8585 JSONTokener x = new JSONTokener (string );
86- o .put ("name" , x .nextTo ('=' ));
86+ jo .put ("name" , x .nextTo ('=' ));
8787 x .next ('=' );
88- o .put ("value" , x .nextTo (';' ));
88+ jo .put ("value" , x .nextTo (';' ));
8989 x .next ();
9090 while (x .more ()) {
91- n = unescape (x .nextTo ("=;" ));
91+ name = unescape (x .nextTo ("=;" ));
9292 if (x .next () != '=' ) {
93- if (n .equals ("secure" )) {
94- v = Boolean .TRUE ;
93+ if (name .equals ("secure" )) {
94+ value = Boolean .TRUE ;
9595 } else {
9696 throw x .syntaxError ("Missing '=' in cookie parameter." );
9797 }
9898 } else {
99- v = unescape (x .nextTo (';' ));
99+ value = unescape (x .nextTo (';' ));
100100 x .next ();
101101 }
102- o .put (n , v );
102+ jo .put (name , value );
103103 }
104- return o ;
104+ return jo ;
105105 }
106106
107107
@@ -111,29 +111,29 @@ public static JSONObject toJSONObject(String string) throws JSONException {
111111 * If the JSONObject contains "expires", "domain", "path", or "secure"
112112 * members, they will be appended to the cookie specification string.
113113 * All other members are ignored.
114- * @param o A JSONObject
114+ * @param jo A JSONObject
115115 * @return A cookie specification string
116116 * @throws JSONException
117117 */
118- public static String toString (JSONObject o ) throws JSONException {
118+ public static String toString (JSONObject jo ) throws JSONException {
119119 StringBuffer sb = new StringBuffer ();
120120
121- sb .append (escape (o .getString ("name" )));
121+ sb .append (escape (jo .getString ("name" )));
122122 sb .append ("=" );
123- sb .append (escape (o .getString ("value" )));
124- if (o .has ("expires" )) {
123+ sb .append (escape (jo .getString ("value" )));
124+ if (jo .has ("expires" )) {
125125 sb .append (";expires=" );
126- sb .append (o .getString ("expires" ));
126+ sb .append (jo .getString ("expires" ));
127127 }
128- if (o .has ("domain" )) {
128+ if (jo .has ("domain" )) {
129129 sb .append (";domain=" );
130- sb .append (escape (o .getString ("domain" )));
130+ sb .append (escape (jo .getString ("domain" )));
131131 }
132- if (o .has ("path" )) {
132+ if (jo .has ("path" )) {
133133 sb .append (";path=" );
134- sb .append (escape (o .getString ("path" )));
134+ sb .append (escape (jo .getString ("path" )));
135135 }
136- if (o .optBoolean ("secure" )) {
136+ if (jo .optBoolean ("secure" )) {
137137 sb .append (";secure" );
138138 }
139139 return sb .toString ();
@@ -142,28 +142,28 @@ public static String toString(JSONObject o) throws JSONException {
142142 /**
143143 * Convert <code>%</code><i>hh</i> sequences to single characters, and
144144 * convert plus to space.
145- * @param s A string that may contain
145+ * @param string A string that may contain
146146 * <code>+</code> <small>(plus)</small> and
147147 * <code>%</code><i>hh</i> sequences.
148148 * @return The unescaped string.
149149 */
150- public static String unescape (String s ) {
151- int len = s .length ();
152- StringBuffer b = new StringBuffer ();
153- for (int i = 0 ; i < len ; ++i ) {
154- char c = s .charAt (i );
150+ public static String unescape (String string ) {
151+ int length = string .length ();
152+ StringBuffer sb = new StringBuffer ();
153+ for (int i = 0 ; i < length ; ++i ) {
154+ char c = string .charAt (i );
155155 if (c == '+' ) {
156156 c = ' ' ;
157- } else if (c == '%' && i + 2 < len ) {
158- int d = JSONTokener .dehexchar (s .charAt (i + 1 ));
159- int e = JSONTokener .dehexchar (s .charAt (i + 2 ));
157+ } else if (c == '%' && i + 2 < length ) {
158+ int d = JSONTokener .dehexchar (string .charAt (i + 1 ));
159+ int e = JSONTokener .dehexchar (string .charAt (i + 2 ));
160160 if (d >= 0 && e >= 0 ) {
161161 c = (char )(d * 16 + e );
162162 i += 2 ;
163163 }
164164 }
165- b .append (c );
165+ sb .append (c );
166166 }
167- return b .toString ();
167+ return sb .toString ();
168168 }
169169}
0 commit comments