From 6bd21074a3512c00e51df5289e099ac0fd11f01c Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Sun, 8 Jan 2006 10:57:46 +0000 Subject: [PATCH] Code clean-up. --- src/text.cpp | 32 +++++++++++++++----------------- src/word.cpp | 6 +++--- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/text.cpp b/src/text.cpp index 8436c44b..1f894484 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -263,22 +263,20 @@ ref text::newFromString(const string& in, const charset& ch) void text::createFromString(const string& in, const charset& ch) { - const string::const_iterator end = in.end(); - string::const_iterator p = in.begin(); - string::const_iterator start = in.begin(); - bool is8bit = false; // is the current word 8-bit? bool prevIs8bit = false; // is previous word 8-bit? unsigned int count = 0; // total number of words removeAllWords(); - for ( ; ; ) + for (string::size_type end = in.size(), pos = 0, start = 0 ; ; ) { - if (p == end || parserHelpers::isSpace(*p)) + if (pos == end || parserHelpers::isSpace(in[pos])) { - if (p != end) - ++p; + if (pos != end) + ++pos; + + const string chunk(in.begin() + start, in.begin() + pos); if (is8bit) { @@ -287,11 +285,11 @@ void text::createFromString(const string& in, const charset& ch) // No need to create a new encoded word, just append // the current word to the previous one. ref w = getWordAt(getWordCount() - 1); - w->getBuffer() += string(start, p); + w->getBuffer() += chunk; } else { - appendWord(vmime::create (string(start, p), ch)); + appendWord(vmime::create (chunk, ch)); prevIs8bit = true; ++count; @@ -302,32 +300,32 @@ void text::createFromString(const string& in, const charset& ch) if (count && !prevIs8bit) { ref w = getWordAt(getWordCount() - 1); - w->getBuffer() += string(start, p); + w->getBuffer() += chunk; } else { appendWord(vmime::create - (string(start, p), charset(charsets::US_ASCII))); + (chunk, charset(charsets::US_ASCII))); prevIs8bit = false; ++count; } } - if (p == end) + if (pos == end) break; is8bit = false; - start = p; + start = pos; } - else if (!parserHelpers::isAscii(*p)) + else if (!parserHelpers::isAscii(in[pos])) { is8bit = true; - ++p; + ++pos; } else { - ++p; + ++pos; } } } diff --git a/src/word.cpp b/src/word.cpp index ccb5d554..45dbc183 100644 --- a/src/word.cpp +++ b/src/word.cpp @@ -91,7 +91,7 @@ ref word::parseNext(const string& buffer, const string::size_type positio while (pos != end && parserHelpers::isSpace(buffer[pos])) ++pos; - unencoded += string(buffer.begin() + startPos, buffer.begin() + endPos); + unencoded += buffer.substr(startPos, endPos - startPos); unencoded += ' '; startPos = pos; @@ -101,7 +101,7 @@ ref word::parseNext(const string& buffer, const string::size_type positio buffer[pos] == '=' && buffer[pos + 1] == '?') { // Check whether there is some unencoded text before - unencoded += string(buffer.begin() + startPos, buffer.begin() + pos); + unencoded += buffer.substr(startPos, pos - startPos); if (!unencoded.empty()) { @@ -183,7 +183,7 @@ ref word::parseNext(const string& buffer, const string::size_type positio if (startPos != pos && !isFirst && prevIsEncoded) unencoded += ' '; - unencoded += string(buffer.begin() + startPos, buffer.begin() + end); + unencoded += buffer.substr(startPos, end - startPos); ref w = vmime::create (unencoded, charset(charsets::US_ASCII)); w->setParsedBounds(position, end);