@@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
28
28
* Convert a web browser cookie specification to a JSONObject and back.
29
29
* JSON and Cookies are both notations for name/value pairs.
30
30
* @author JSON.org
31
- * @version 2008-09-18
31
+ * @version 2010-12-24
32
32
*/
33
33
public class Cookie {
34
34
@@ -48,8 +48,8 @@ public static String escape(String string) {
48
48
char c ;
49
49
String s = string .trim ();
50
50
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 ) {
53
53
c = s .charAt (i );
54
54
if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';' ) {
55
55
sb .append ('%' );
@@ -79,29 +79,29 @@ public static String escape(String string) {
79
79
* @throws JSONException
80
80
*/
81
81
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 ;
85
85
JSONTokener x = new JSONTokener (string );
86
- o .put ("name" , x .nextTo ('=' ));
86
+ jo .put ("name" , x .nextTo ('=' ));
87
87
x .next ('=' );
88
- o .put ("value" , x .nextTo (';' ));
88
+ jo .put ("value" , x .nextTo (';' ));
89
89
x .next ();
90
90
while (x .more ()) {
91
- n = unescape (x .nextTo ("=;" ));
91
+ name = unescape (x .nextTo ("=;" ));
92
92
if (x .next () != '=' ) {
93
- if (n .equals ("secure" )) {
94
- v = Boolean .TRUE ;
93
+ if (name .equals ("secure" )) {
94
+ value = Boolean .TRUE ;
95
95
} else {
96
96
throw x .syntaxError ("Missing '=' in cookie parameter." );
97
97
}
98
98
} else {
99
- v = unescape (x .nextTo (';' ));
99
+ value = unescape (x .nextTo (';' ));
100
100
x .next ();
101
101
}
102
- o .put (n , v );
102
+ jo .put (name , value );
103
103
}
104
- return o ;
104
+ return jo ;
105
105
}
106
106
107
107
@@ -111,29 +111,29 @@ public static JSONObject toJSONObject(String string) throws JSONException {
111
111
* If the JSONObject contains "expires", "domain", "path", or "secure"
112
112
* members, they will be appended to the cookie specification string.
113
113
* All other members are ignored.
114
- * @param o A JSONObject
114
+ * @param jo A JSONObject
115
115
* @return A cookie specification string
116
116
* @throws JSONException
117
117
*/
118
- public static String toString (JSONObject o ) throws JSONException {
118
+ public static String toString (JSONObject jo ) throws JSONException {
119
119
StringBuffer sb = new StringBuffer ();
120
120
121
- sb .append (escape (o .getString ("name" )));
121
+ sb .append (escape (jo .getString ("name" )));
122
122
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" )) {
125
125
sb .append (";expires=" );
126
- sb .append (o .getString ("expires" ));
126
+ sb .append (jo .getString ("expires" ));
127
127
}
128
- if (o .has ("domain" )) {
128
+ if (jo .has ("domain" )) {
129
129
sb .append (";domain=" );
130
- sb .append (escape (o .getString ("domain" )));
130
+ sb .append (escape (jo .getString ("domain" )));
131
131
}
132
- if (o .has ("path" )) {
132
+ if (jo .has ("path" )) {
133
133
sb .append (";path=" );
134
- sb .append (escape (o .getString ("path" )));
134
+ sb .append (escape (jo .getString ("path" )));
135
135
}
136
- if (o .optBoolean ("secure" )) {
136
+ if (jo .optBoolean ("secure" )) {
137
137
sb .append (";secure" );
138
138
}
139
139
return sb .toString ();
@@ -142,28 +142,28 @@ public static String toString(JSONObject o) throws JSONException {
142
142
/**
143
143
* Convert <code>%</code><i>hh</i> sequences to single characters, and
144
144
* convert plus to space.
145
- * @param s A string that may contain
145
+ * @param string A string that may contain
146
146
* <code>+</code> <small>(plus)</small> and
147
147
* <code>%</code><i>hh</i> sequences.
148
148
* @return The unescaped string.
149
149
*/
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 );
155
155
if (c == '+' ) {
156
156
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 ));
160
160
if (d >= 0 && e >= 0 ) {
161
161
c = (char )(d * 16 + e );
162
162
i += 2 ;
163
163
}
164
164
}
165
- b .append (c );
165
+ sb .append (c );
166
166
}
167
- return b .toString ();
167
+ return sb .toString ();
168
168
}
169
169
}
0 commit comments