Code clean-up.

This commit is contained in:
Vincent Richard 2006-01-08 10:57:46 +00:00
parent f259c6e4d7
commit 6bd21074a3
2 changed files with 18 additions and 20 deletions

View File

@ -263,22 +263,20 @@ ref <text> text::newFromString(const string& in, const charset& ch)
void text::createFromString(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 is8bit = false; // is the current word 8-bit?
bool prevIs8bit = false; // is previous word 8-bit? bool prevIs8bit = false; // is previous word 8-bit?
unsigned int count = 0; // total number of words unsigned int count = 0; // total number of words
removeAllWords(); 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) if (pos != end)
++p; ++pos;
const string chunk(in.begin() + start, in.begin() + pos);
if (is8bit) 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 // No need to create a new encoded word, just append
// the current word to the previous one. // the current word to the previous one.
ref <word> w = getWordAt(getWordCount() - 1); ref <word> w = getWordAt(getWordCount() - 1);
w->getBuffer() += string(start, p); w->getBuffer() += chunk;
} }
else else
{ {
appendWord(vmime::create <word>(string(start, p), ch)); appendWord(vmime::create <word>(chunk, ch));
prevIs8bit = true; prevIs8bit = true;
++count; ++count;
@ -302,32 +300,32 @@ void text::createFromString(const string& in, const charset& ch)
if (count && !prevIs8bit) if (count && !prevIs8bit)
{ {
ref <word> w = getWordAt(getWordCount() - 1); ref <word> w = getWordAt(getWordCount() - 1);
w->getBuffer() += string(start, p); w->getBuffer() += chunk;
} }
else else
{ {
appendWord(vmime::create <word> appendWord(vmime::create <word>
(string(start, p), charset(charsets::US_ASCII))); (chunk, charset(charsets::US_ASCII)));
prevIs8bit = false; prevIs8bit = false;
++count; ++count;
} }
} }
if (p == end) if (pos == end)
break; break;
is8bit = false; is8bit = false;
start = p; start = pos;
} }
else if (!parserHelpers::isAscii(*p)) else if (!parserHelpers::isAscii(in[pos]))
{ {
is8bit = true; is8bit = true;
++p; ++pos;
} }
else else
{ {
++p; ++pos;
} }
} }
} }

View File

@ -91,7 +91,7 @@ ref <word> word::parseNext(const string& buffer, const string::size_type positio
while (pos != end && parserHelpers::isSpace(buffer[pos])) while (pos != end && parserHelpers::isSpace(buffer[pos]))
++pos; ++pos;
unencoded += string(buffer.begin() + startPos, buffer.begin() + endPos); unencoded += buffer.substr(startPos, endPos - startPos);
unencoded += ' '; unencoded += ' ';
startPos = pos; startPos = pos;
@ -101,7 +101,7 @@ ref <word> word::parseNext(const string& buffer, const string::size_type positio
buffer[pos] == '=' && buffer[pos + 1] == '?') buffer[pos] == '=' && buffer[pos + 1] == '?')
{ {
// Check whether there is some unencoded text before // 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()) if (!unencoded.empty())
{ {
@ -183,7 +183,7 @@ ref <word> word::parseNext(const string& buffer, const string::size_type positio
if (startPos != pos && !isFirst && prevIsEncoded) if (startPos != pos && !isFirst && prevIsEncoded)
unencoded += ' '; unencoded += ' ';
unencoded += string(buffer.begin() + startPos, buffer.begin() + end); unencoded += buffer.substr(startPos, end - startPos);
ref <word> w = vmime::create <word>(unencoded, charset(charsets::US_ASCII)); ref <word> w = vmime::create <word>(unencoded, charset(charsets::US_ASCII));
w->setParsedBounds(position, end); w->setParsedBounds(position, end);