From c9119effd784055d27b71a567c3fbd0d6e7b03b0 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 4 Oct 2019 21:53:04 +0200 Subject: [PATCH] Reduce indent by 3 levels in findNextBoundary --- src/vmime/body.cpp | 96 +++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/src/vmime/body.cpp b/src/vmime/body.cpp index 44679390..b7f491a1 100644 --- a/src/vmime/body.cpp +++ b/src/vmime/body.cpp @@ -65,7 +65,7 @@ size_t body::findNextBoundaryPosition( size_t pos = position; - while (pos != npos && pos < end) { + for (; pos != npos && pos < end; ++pos) { pos = parser->findNext(boundary, pos); @@ -73,60 +73,62 @@ size_t body::findNextBoundaryPosition( 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 - size_t advance = 0; + // Skip transport padding bytes (SPACE or HTAB), if any + 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') { - ++advance; - } else { - 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; - } - } + if (c == ' ' || c == '\t') { + ++advance; + } else { + break; } } - // Boundary is a prefix of another, continue the search - pos++; + // Ensure the bytes before boundary are "[LF]--": boundary should be + // 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;