@@ -176,7 +176,7 @@ private Feature(boolean defaultState) {
176
176
/* State
177
177
/**********************************************************************
178
178
*/
179
-
179
+
180
180
/**
181
181
* Information about parser context, context in which
182
182
* the next token is to be parsed (root, array, object).
@@ -194,18 +194,18 @@ private Feature(boolean defaultState) {
194
194
* String value for the current column, if accessed.
195
195
*/
196
196
protected String _currentValue ;
197
-
197
+
198
198
/**
199
199
* Index of the column we are exposing
200
200
*/
201
201
protected int _columnIndex ;
202
-
202
+
203
203
/**
204
204
* Current logical state of the parser; one of <code>STATE_</code>
205
205
* constants.
206
206
*/
207
207
protected int _state = STATE_DOC_START ;
208
-
208
+
209
209
/**
210
210
* We will hold on to decoded binary data, for duration of
211
211
* current event, so that multiple calls to
@@ -225,7 +225,7 @@ private Feature(boolean defaultState) {
225
225
protected String _arrayValue ;
226
226
227
227
protected char _arraySeparator ;
228
-
228
+
229
229
/*
230
230
/**********************************************************************
231
231
/* Helper objects
@@ -242,15 +242,15 @@ private Feature(boolean defaultState) {
242
242
* of doubled-quotes, escaped characters.
243
243
*/
244
244
protected final TextBuffer _textBuffer ;
245
-
245
+
246
246
protected ByteArrayBuilder _byteArrayBuilder ;
247
-
247
+
248
248
/*
249
249
/**********************************************************************
250
250
/* Life-cycle
251
251
/**********************************************************************
252
252
*/
253
-
253
+
254
254
public CsvParser (CsvIOContext ctxt , int parserFeatures , int csvFeatures ,
255
255
ObjectCodec codec , Reader reader )
256
256
{
@@ -282,7 +282,7 @@ public Version version() {
282
282
/* Overridden methods
283
283
/**********************************************************
284
284
*/
285
-
285
+
286
286
@ Override
287
287
public ObjectCodec getCodec () {
288
288
return _objectCodec ;
@@ -292,7 +292,7 @@ public ObjectCodec getCodec() {
292
292
public void setCodec (ObjectCodec c ) {
293
293
_objectCodec = c ;
294
294
}
295
-
295
+
296
296
@ Override
297
297
public boolean canUseSchema (FormatSchema schema ) {
298
298
return (schema instanceof CsvSchema );
@@ -692,13 +692,30 @@ protected JsonToken _handleArrayValue() throws IOException
692
692
return JsonToken .END_ARRAY ;
693
693
}
694
694
int end = _arrayValue .indexOf (_arraySeparator , offset );
695
+
695
696
if (end < 0 ) { // last value
696
- _currentValue = (offset == 0 ) ? _arrayValue : _arrayValue .substring (offset );
697
- _arrayValueStart = end ;
697
+ _arrayValueStart = end ; // end marker, regardless
698
+
699
+ // 11-Feb-2015, tatu: Tricky, As per [dataformat-csv#66]; empty Strings really
700
+ // should not emit any values. Not sure if trim
701
+ if (offset == 0 ) { // no separator
702
+ // for now, let's use trimming for checking
703
+ if (_arrayValue .isEmpty () || _arrayValue .trim ().isEmpty ()) {
704
+ _parsingContext = _parsingContext .getParent ();
705
+ _state = STATE_NEXT_ENTRY ;
706
+ return JsonToken .END_ARRAY ;
707
+ }
708
+ _currentValue = _arrayValue ;
709
+ } else {
710
+ _currentValue = _arrayValue .substring (offset );
711
+ }
698
712
} else {
699
713
_currentValue = _arrayValue .substring (offset , end );
700
714
_arrayValueStart = end +1 ;
701
715
}
716
+ if (isEnabled (Feature .TRIM_SPACES )) {
717
+ _currentValue = _currentValue .trim ();
718
+ }
702
719
return JsonToken .VALUE_STRING ;
703
720
}
704
721
0 commit comments