Reduce indent by 3 levels in findNextBoundary

This commit is contained in:
Jan Engelhardt 2019-10-04 21:53:04 +02:00
parent 6de75f0c95
commit c9119effd7

View File

@ -65,7 +65,7 @@ size_t body::findNextBoundaryPosition(
size_t pos = position; size_t pos = position;
while (pos != npos && pos < end) { for (; pos != npos && pos < end; ++pos) {
pos = parser->findNext(boundary, pos); pos = parser->findNext(boundary, pos);
@ -73,60 +73,62 @@ size_t body::findNextBoundaryPosition(
break; // not found break; // not found
} }
if (pos != 0) { if (pos == 0) {
// Boundary is a prefix of another, continue the search (same for the other "continue"s)
continue;
}
// Skip transport padding bytes (SPACE or HTAB), if any // Skip transport padding bytes (SPACE or HTAB), if any
size_t advance = 0; size_t advance = 0;
while (pos != 0) { while (pos != 0) {
parser->seek(pos - advance - 1); parser->seek(pos - advance - 1);
const byte_t c = parser->peekByte(); const byte_t c = parser->peekByte();
if (c == ' ' || c == '\t') { if (c == ' ' || c == '\t') {
++advance; ++advance;
} else { } else {
break; break;
}
}
// Ensure the bytes before boundary are "[LF]--": boundary should be
// at the beginning of a line, and should start with "--"
if (pos - advance >= 3) {
parser->seek(pos - advance - 3);
if (parser->matchBytes("\n--", 3)) {
parser->seek(pos + boundary.length());
const byte_t next = parser->peekByte();
// Boundary should be followed by a new line or a dash
if (next == '\r' || next == '\n' || next == '-') {
// Get rid of the "[CR]" just before "[LF]--", if any
if (pos - advance >= 4) {
parser->seek(pos - advance - 4);
if (parser->peekByte() == '\r') {
advance++;
}
}
*boundaryStart = pos - advance - 3;
*boundaryEnd = pos + boundary.length();
return pos;
}
}
} }
} }
// Boundary is a prefix of another, continue the search // Ensure the bytes before boundary are "[LF]--": boundary should be
pos++; // at the beginning of a line, and should start with "--"
if (pos - advance < 3) {
continue;
}
parser->seek(pos - advance - 3);
if (!parser->matchBytes("\n--", 3)) {
continue;
}
parser->seek(pos + boundary.length());
const byte_t next = parser->peekByte();
// Boundary should be followed by a new line or a dash
if (next != '\r' && next != '\n' && next != '-') {
continue;
}
// Get rid of the "[CR]" just before "[LF]--", if any
if (pos - advance >= 4) {
parser->seek(pos - advance - 4);
if (parser->peekByte() == '\r') {
advance++;
}
}
*boundaryStart = pos - advance - 3;
*boundaryEnd = pos + boundary.length();
return pos;
} }
return pos; return pos;