Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Commit

Permalink
Implemnt #56
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 1, 2015
1 parent 95b8847 commit 4b2e26b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
7 changes: 7 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ Wei Li (wli600@github)
* Contributed fix for 54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter
or end-of-line happened to be the leading character of a segment buffer
(2.4.4)

Luke Nezda (nezda@github)

* Suggested #56: Support comments (either via `CsvSchema`, or using std
`JsonParser.Feature.ALLOW_YAML_COMMENTS.
(requested by nezda@github)
(2.5.0)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project: jackson-dataformat-csv
#50: Support `JsonGenerator.Feature.IGNORE_KNOWN` for CSV, to ignoring extra columns
#53: Add a way to specify "null value" (String) for `CsvGenerator` to use when writing `null`s
(part of `CsvSchema`; method `withNullValue()`)
#56: Support comments (either via `CsvSchema`, or using std `JsonParser.Feature.ALLOW_YAML_COMMENTS.
(requested by nezda@github)
#57: Support simple array types
#61: Add a feature to always quote non-numeric values: `CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ protected JsonToken _handleStartDoc() throws IOException
if (_schema.skipsFirstDataRow()) {
_reader.skipLine();
}
// also, if comments enabled, may need to skip leading ones
_reader.skipLeadingComments();

/* Only one real complication, actually; empy documents (zero bytes).
* Those have no entries. Should be easy enough to detect like so:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ public boolean startNewLine() throws IOException
}

if (_allowComments && _inputBuffer[_inputPtr] == '#') {
int i = _skipCommentLine();
int i = _skipCommentLines();
// end-of-input?
if (i < 0) {
return false;
Expand All @@ -530,6 +530,37 @@ public boolean startNewLine() throws IOException
return true;
}

public void skipLeadingComments() throws IOException
{
if (_allowComments) {
if ((_inputPtr < _inputEnd) || loadMore()) {
if (_inputBuffer[_inputPtr] == '#') {
_skipCommentLines();
--_inputPtr;
}
}
}
}

protected int _skipCommentLines() throws IOException
{
while ((_inputPtr < _inputEnd) || loadMore()) {
char ch = _inputBuffer[_inputPtr++];
if (ch >= ' ' || (ch != '\r' && ch != '\n')) {
continue;
}
_pendingLF = ch;
_handleLF();

// Ok, skipped the end of the line. Check next one...
int i = _nextChar();
if (i != INT_HASH) {
return i;
}
}
return -1; // end of input
}

public boolean skipLine() throws IOException
{
if (_pendingLF != 0) {
Expand Down Expand Up @@ -674,30 +705,6 @@ public JsonToken nextNumberOrString() throws IOException
}
return JsonToken.VALUE_STRING;
}

protected int _skipCommentLine() throws IOException
{
while ((_inputPtr < _inputEnd) || loadMore()) {
char ch = _inputBuffer[_inputPtr++];
if (ch >= ' ' || (ch != '\r' && ch != '\n')) {
continue;
}
_pendingLF = ch;
_handleLF();

// Ok, skipped the end of the line. And parse next one...
int i;
if (_trimSpaces) {
i = _skipLeadingSpace();
} else {
i = _nextChar();
}
if (i != INT_HASH) {
return i;
}
}
return -1; // end of input
}

/*
/**********************************************************************
Expand Down

0 comments on commit 4b2e26b

Please sign in to comment.