From 4c7e3ed836c24bf55a85ccf7d08f269aaa47121c Mon Sep 17 00:00:00 2001 From: Roberto Raggi <roberto.raggi@nokia.com> Date: Tue, 3 Mar 2009 11:14:12 +0100 Subject: [PATCH] Add the _right_ number of spaces. --- src/libs/cplusplus/pp-engine.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 1f3750b1c2b..321666ea4c4 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -692,8 +692,24 @@ void Preprocessor::preprocess(const QByteArray &fileName, const QByteArray &sour if (_dot->joined) _result->append("\\\n"); - else if (_dot->whitespace) - _result->append(' '); + else if (_dot->whitespace) { + TokenIterator begin = _tokens.constBegin(); + Q_ASSERT(begin != first); + + const unsigned endOfPreviousToken = (_dot - 1)->end(); + const unsigned beginOfToken = _dot->begin(); + + const char *it = _source.constBegin() + endOfPreviousToken; + const char *end = _source.constBegin() + beginOfToken; + + for (; it != end; ++it) { + if (std::isspace(*it)) + _result->append(*it); + + else + _result->append(' '); + } + } if (_dot->isNot(T_IDENTIFIER)) { _result->append(tokenSpell(*_dot)); -- GitLab