Skip to content

Commit

Permalink
Fix issue handling new line characters
Browse files Browse the repository at this point in the history
  • Loading branch information
LakshanWeerasinghe committed May 24, 2024
1 parent db993a7 commit 4153e1a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,4 @@ public class Constants {
static final String NAME = "Name";
static final String YAML = "yaml";
static final String DATA_YAML = "data.yaml";

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public boolean forward(int k) {
}

private boolean hasNewLine(int codePoint) {
return codePoint == '\n' || codePoint == '\r' && peek() == '\n';
return codePoint == '\n';
}

private boolean checkAndReadData(int k) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public static void iterate(LexerState sm, Scan scan, Token.TokenType token, bool
if (include && sm.peek() != '\n') {
sm.forward();
}
if (include && sm.peek() != '\r' && sm.peek(1) != '\n') {
sm.forward(2);
}
sm.tokenize(token);
return;
}
Expand Down Expand Up @@ -422,7 +425,7 @@ public boolean scan(LexerState sm) throws Error.YamlParserException {
peekAtIndex = sm.peek(++numWhitespace);
}

if (peekAtIndex == -1 || peekAtIndex == '\n') {
if (peekAtIndex == -1 || LINE_BREAK_PATTERN.pattern(peekAtIndex)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public static LexerState.State scanTokens(LexerState state) throws Error.YamlPar
return state.getState();
}

// Check for line breaks when reading from string
if (state.peek() == '\r' && state.peek(1) == '\n' && state.getState() != LEXER_DOUBLE_QUOTE) {
state.setNewLine(true);
state.forward();
state.tokenize(EOL);
return state.getState();
}

return state.getState().transition(state);
}
}

0 comments on commit 4153e1a

Please sign in to comment.