@@ -64,18 +64,18 @@ private static String getValue(JSONTokener x) throws JSONException {
6464 return null ;
6565 case '"' :
6666 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+ }
7474 if (c == 0 || c == '\n' || c == '\r' ) {
7575 throw x .syntaxError ("Missing close quote '" + q + "'." );
7676 }
7777 sb .append (c );
78- }
78+ }
7979 return sb .toString ();
8080 case ',' :
8181 x .back ();
@@ -98,7 +98,7 @@ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
9898 String value = getValue (x );
9999 char c = x .next ();
100100 if (value == null ||
101- (ja .length () == 0 && value .length () == 0 && c != ',' )) {
101+ (ja .length () == 0 && value .length () == 0 && c != ',' )) {
102102 return null ;
103103 }
104104 ja .put (value );
@@ -135,43 +135,43 @@ public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x)
135135 }
136136
137137 /**
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+ }
173173
174- /**
174+ /**
175175 * Produce a JSONArray of JSONObjects from a comma delimited text string,
176176 * using the first row as a source of names.
177177 * @param string The comma delimited text.
0 commit comments