forked from qt-creator/qt-creator
add ProString::prepend()
Change-Id: I2dc905470c90eeba15f0f00412405a9a1a2ddcc7 Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
This commit is contained in:
@@ -156,14 +156,14 @@ QString &ProString::toQString(QString &tmp) const
|
||||
return tmp.setRawData(m_string.constData() + m_offset, m_length);
|
||||
}
|
||||
|
||||
QChar *ProString::prepareAppend(int extraLen)
|
||||
QChar *ProString::prepareExtend(int extraLen, int thisTarget, int extraTarget)
|
||||
{
|
||||
if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) {
|
||||
m_string.reserve(0); // Prevent the resize() below from reallocating
|
||||
QChar *ptr = (QChar *)m_string.constData();
|
||||
if (m_offset)
|
||||
memmove(ptr, ptr + m_offset, m_length * 2);
|
||||
ptr += m_length;
|
||||
if (m_offset != thisTarget)
|
||||
memmove(ptr + thisTarget, ptr + m_offset, m_length * 2);
|
||||
ptr += extraTarget;
|
||||
m_offset = 0;
|
||||
m_length += extraLen;
|
||||
m_string.resize(m_length);
|
||||
@@ -172,13 +172,28 @@ QChar *ProString::prepareAppend(int extraLen)
|
||||
} else {
|
||||
QString neu(m_length + extraLen, Qt::Uninitialized);
|
||||
QChar *ptr = (QChar *)neu.constData();
|
||||
memcpy(ptr, m_string.constData() + m_offset, m_length * 2);
|
||||
ptr += m_length;
|
||||
memcpy(ptr + thisTarget, m_string.constData() + m_offset, m_length * 2);
|
||||
ptr += extraTarget;
|
||||
*this = ProString(neu);
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
ProString &ProString::prepend(const ProString &other)
|
||||
{
|
||||
if (other.m_length) {
|
||||
if (!m_length) {
|
||||
*this = other;
|
||||
} else {
|
||||
QChar *ptr = prepareExtend(other.m_length, other.m_length, 0);
|
||||
memcpy(ptr, other.constData(), other.m_length * 2);
|
||||
if (!m_file)
|
||||
m_file = other.m_file;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
// If pending != 0, prefix with space if appending to non-empty non-pending
|
||||
ProString &ProString::append(const ProString &other, bool *pending)
|
||||
{
|
||||
@@ -188,10 +203,10 @@ ProString &ProString::append(const ProString &other, bool *pending)
|
||||
} else {
|
||||
QChar *ptr;
|
||||
if (pending && !*pending) {
|
||||
ptr = prepareAppend(1 + other.m_length);
|
||||
ptr = prepareExtend(1 + other.m_length, 0, m_length);
|
||||
*ptr++ = 32;
|
||||
} else {
|
||||
ptr = prepareAppend(other.m_length);
|
||||
ptr = prepareExtend(other.m_length, 0, m_length);
|
||||
}
|
||||
memcpy(ptr, other.m_string.constData() + other.m_offset, other.m_length * 2);
|
||||
if (other.m_file)
|
||||
@@ -224,7 +239,7 @@ ProString &ProString::append(const ProStringList &other, bool *pending, bool ski
|
||||
else
|
||||
totalLength--;
|
||||
|
||||
QChar *ptr = prepareAppend(totalLength);
|
||||
QChar *ptr = prepareExtend(totalLength, 0, m_length);
|
||||
for (int i = startIdx; i < sz; ++i) {
|
||||
if (putSpace)
|
||||
*ptr++ = 32;
|
||||
|
@@ -78,6 +78,7 @@ public:
|
||||
ProString &setSource(const ProFile *pro) { m_file = pro; return *this; }
|
||||
const ProFile *sourceFile() const { return m_file; }
|
||||
|
||||
ProString &prepend(const ProString &other);
|
||||
ProString &operator+=(const ProString &other);
|
||||
ProString &append(const ProString &other, bool *pending = 0);
|
||||
ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false);
|
||||
@@ -155,7 +156,7 @@ private:
|
||||
int m_offset, m_length;
|
||||
const ProFile *m_file;
|
||||
mutable uint m_hash;
|
||||
QChar *prepareAppend(int extraLen);
|
||||
QChar *prepareExtend(int extraLen, int thisTarget, int extraTarget);
|
||||
uint updatedHash() const;
|
||||
friend uint qHash(const ProString &str);
|
||||
friend QString operator+(const ProString &one, const ProString &two);
|
||||
|
Reference in New Issue
Block a user