@@ -219,53 +219,57 @@ void printAndQuote(final CharSequence value, final int offset, final int len) th
219219 final char delimChar = format .getDelimiter ();
220220 final char quoteChar = format .getQuoteChar ();
221221
222- if (len <= 0 ) {
223- // always quote an empty token that is the first
224- // on the line, as it may be the only thing on the
225- // line. If it were not quoted in that case,
226- // an empty line has no tokens.
227- if (first ) {
228- quote = true ;
229- }
222+ if (format .getQuotePolicy () == Quote .ALL ) {
223+ quote = true ;
230224 } else {
231- char c = value .charAt (pos );
232-
233- // Hmmm, where did this rule come from?
234- if (first && (c < '0' || (c > '9' && c < 'A' ) || (c > 'Z' && c < 'a' ) || (c > 'z' ))) {
235- quote = true ;
236- // } else if (c == ' ' || c == '\f' || c == '\t') {
237- } else if (c <= COMMENT ) {
238- // Some other chars at the start of a value caused the parser to fail, so for now
239- // encapsulate if we start in anything less than '#'. We are being conservative
240- // by including the default comment char too.
241- quote = true ;
225+ if (len <= 0 ) {
226+ // always quote an empty token that is the first
227+ // on the line, as it may be the only thing on the
228+ // line. If it were not quoted in that case,
229+ // an empty line has no tokens.
230+ if (first ) {
231+ quote = true ;
232+ }
242233 } else {
243- while (pos < end ) {
244- c = value .charAt (pos );
245- if (c == LF || c == CR || c == quoteChar || c == delimChar ) {
246- quote = true ;
247- break ;
234+ char c = value .charAt (pos );
235+
236+ // Hmmm, where did this rule come from?
237+ if (first && (c < '0' || (c > '9' && c < 'A' ) || (c > 'Z' && c < 'a' ) || (c > 'z' ))) {
238+ quote = true ;
239+ // } else if (c == ' ' || c == '\f' || c == '\t') {
240+ } else if (c <= COMMENT ) {
241+ // Some other chars at the start of a value caused the parser to fail, so for now
242+ // encapsulate if we start in anything less than '#'. We are being conservative
243+ // by including the default comment char too.
244+ quote = true ;
245+ } else {
246+ while (pos < end ) {
247+ c = value .charAt (pos );
248+ if (c == LF || c == CR || c == quoteChar || c == delimChar ) {
249+ quote = true ;
250+ break ;
251+ }
252+ pos ++;
248253 }
249- pos ++;
250- }
251254
252- if (!quote ) {
253- pos = end - 1 ;
254- c = value .charAt (pos );
255- // if (c == ' ' || c == '\f' || c == '\t') {
256- // Some other chars at the end caused the parser to fail, so for now
257- // encapsulate if we end in anything less than ' '
258- if (c <= SP ) {
259- quote = true ;
255+ if (!quote ) {
256+ pos = end - 1 ;
257+ c = value .charAt (pos );
258+ // if (c == ' ' || c == '\f' || c == '\t') {
259+ // Some other chars at the end caused the parser to fail, so for now
260+ // encapsulate if we end in anything less than ' '
261+ if (c <= SP ) {
262+ quote = true ;
263+ }
260264 }
261265 }
262266 }
263- }
264267
265- if (!quote ) {
266- // no encapsulation needed - write out the original value
267- out .append (value , start , end );
268- return ;
268+ if (!quote ) {
269+ // no encapsulation needed - write out the original value
270+ out .append (value , start , end );
271+ return ;
272+ }
269273 }
270274
271275 // we hit something that needed encapsulation
0 commit comments