in src/main/java/com/univocity/parsers/fixed/FixedWidthParser.java [133:241]
protected void parseRecord() {
if (ch == newLine && skipEmptyLines) {
return;
}
boolean matched = false;
if (lookaheadFormats != null || lookbehindFormats != null) {
if (initializeLookaheadInput) {
initializeLookaheadInput = false;
this.lookaheadInput = new LookaheadCharInputReader(input, newLine, whitespaceRangeStart);
this.input = lookaheadInput;
}
lookaheadInput.lookahead(maxLookupLength);
if (lookaheadFormats != null) {
for (int i = 0; i < lookaheadFormats.length; i++) {
if (lookaheadInput.matches(ch, lookaheadFormats[i].value, wildcard)) {
lengths = lookaheadFormats[i].lengths;
alignments = lookaheadFormats[i].alignments;
paddings = lookaheadFormats[i].paddings;
ignore = lookaheadFormats[i].ignore;
lookupFormat = lookaheadFormats[i];
matched = true;
break;
}
}
if (lookbehindFormats != null && matched) {
lookbehindFormat = null;
for (int i = 0; i < lookbehindFormats.length; i++) {
if (lookaheadInput.matches(ch, lookbehindFormats[i].value, wildcard)) {
lookbehindFormat = lookbehindFormats[i];
break;
}
}
}
} else {
for (int i = 0; i < lookbehindFormats.length; i++) {
if (lookaheadInput.matches(ch, lookbehindFormats[i].value, wildcard)) {
lookbehindFormat = lookbehindFormats[i];
matched = true;
lengths = rootLengths;
ignore = rootIgnore;
break;
}
}
}
if (!matched) {
if (lookbehindFormat == null) {
if (rootLengths == null) {
throw new TextParsingException(context, "Cannot process input with the given configuration. No default field lengths defined and no lookahead/lookbehind value match '" + lookaheadInput.getLookahead(ch) + '\'');
}
lengths = rootLengths;
alignments = rootAlignments;
paddings = rootPaddings;
ignore = rootIgnore;
lookupFormat = null;
} else {
lengths = lookbehindFormat.lengths;
alignments = lookbehindFormat.alignments;
paddings = lookbehindFormat.paddings;
ignore = lookbehindFormat.ignore;
lookupFormat = lookbehindFormat;
}
}
}
int i;
for (i = 0; i < lengths.length; i++) {
length = lengths[i];
if (paddings != null) {
padding = useDefaultPadding ? defaultPadding : paddings[i];
}
if (alignments != null) {
alignment = alignments[i];
}
skipPadding();
if (ignoreLeadingWhitespace) {
skipWhitespace();
}
if (recordEndsOnNewLine) {
readValueUntilNewLine();
if (ch == newLine) {
output.valueParsed();
useDefaultPadding = false;
return;
}
} else if (length > 0) {
readValue();
if (i + 1 < lengths.length) {
ch = input.nextChar();
}
}
if (ignore[i]) {
output.appender.reset();
} else {
output.valueParsed();
}
}
if (skipToNewLine) {
skipToNewLine();
}
useDefaultPadding = false;
}