@@ -64,18 +64,18 @@ private static String getValue(JSONTokener x) throws JSONException {
64
64
return null ;
65
65
case '"' :
66
66
case '\'' :
67
- q = c ;
68
- sb = new StringBuffer ();
69
- for (;;) {
70
- c = x .next ();
71
- if (c == q ) {
72
- break ;
73
- }
67
+ q = c ;
68
+ sb = new StringBuffer ();
69
+ for (;;) {
70
+ c = x .next ();
71
+ if (c == q ) {
72
+ break ;
73
+ }
74
74
if (c == 0 || c == '\n' || c == '\r' ) {
75
75
throw x .syntaxError ("Missing close quote '" + q + "'." );
76
76
}
77
77
sb .append (c );
78
- }
78
+ }
79
79
return sb .toString ();
80
80
case ',' :
81
81
x .back ();
@@ -98,7 +98,7 @@ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
98
98
String value = getValue (x );
99
99
char c = x .next ();
100
100
if (value == null ||
101
- (ja .length () == 0 && value .length () == 0 && c != ',' )) {
101
+ (ja .length () == 0 && value .length () == 0 && c != ',' )) {
102
102
return null ;
103
103
}
104
104
ja .put (value );
@@ -135,43 +135,43 @@ public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
135
135
}
136
136
137
137
/**
138
- * Produce a comma delimited text row from a JSONArray. Values containing
139
- * the comma character will be quoted. Troublesome characters may be
140
- * removed.
141
- * @param ja A JSONArray of strings.
142
- * @return A string ending in NEWLINE.
143
- */
144
- public static String rowToString (JSONArray ja ) {
145
- StringBuffer sb = new StringBuffer ();
146
- for (int i = 0 ; i < ja .length (); i += 1 ) {
147
- if (i > 0 ) {
148
- sb .append (',' );
149
- }
150
- Object object = ja .opt (i );
151
- if (object != null ) {
152
- String string = object .toString ();
153
- if (string .length () > 0 && (string .indexOf (',' ) >= 0 ||
154
- string .indexOf ('\n' ) >= 0 || string .indexOf ('\r' ) >= 0 ||
155
- string .indexOf (0 ) >= 0 || string .charAt (0 ) == '"' )) {
156
- sb .append ('"' );
157
- int length = string .length ();
158
- for (int j = 0 ; j < length ; j += 1 ) {
159
- char c = string .charAt (j );
160
- if (c >= ' ' && c != '"' ) {
161
- sb .append (c );
162
- }
163
- }
164
- sb .append ('"' );
165
- } else {
166
- sb .append (string );
167
- }
168
- }
169
- }
170
- sb .append ('\n' );
171
- return sb .toString ();
172
- }
138
+ * Produce a comma delimited text row from a JSONArray. Values containing
139
+ * the comma character will be quoted. Troublesome characters may be
140
+ * removed.
141
+ * @param ja A JSONArray of strings.
142
+ * @return A string ending in NEWLINE.
143
+ */
144
+ public static String rowToString (JSONArray ja ) {
145
+ StringBuffer sb = new StringBuffer ();
146
+ for (int i = 0 ; i < ja .length (); i += 1 ) {
147
+ if (i > 0 ) {
148
+ sb .append (',' );
149
+ }
150
+ Object object = ja .opt (i );
151
+ if (object != null ) {
152
+ String string = object .toString ();
153
+ if (string .length () > 0 && (string .indexOf (',' ) >= 0 ||
154
+ string .indexOf ('\n' ) >= 0 || string .indexOf ('\r' ) >= 0 ||
155
+ string .indexOf (0 ) >= 0 || string .charAt (0 ) == '"' )) {
156
+ sb .append ('"' );
157
+ int length = string .length ();
158
+ for (int j = 0 ; j < length ; j += 1 ) {
159
+ char c = string .charAt (j );
160
+ if (c >= ' ' && c != '"' ) {
161
+ sb .append (c );
162
+ }
163
+ }
164
+ sb .append ('"' );
165
+ } else {
166
+ sb .append (string );
167
+ }
168
+ }
169
+ }
170
+ sb .append ('\n' );
171
+ return sb .toString ();
172
+ }
173
173
174
- /**
174
+ /**
175
175
* Produce a JSONArray of JSONObjects from a comma delimited text string,
176
176
* using the first row as a source of names.
177
177
* @param string The comma delimited text.
0 commit comments