From 422485c89230e8b17c494a1e4cc583cd418aa399 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 21 Aug 2012 19:40:14 +0200 Subject: [PATCH] add a bunch of ProString::append() overloads Change-Id: I9f1f62d8ba57a1bec2c55fe32709b2f6db0f7882 Reviewed-by: Daniel Teske --- src/shared/proparser/proitems.cpp | 23 +++++++++++++++++++++++ src/shared/proparser/proitems.h | 10 +++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/shared/proparser/proitems.cpp b/src/shared/proparser/proitems.cpp index 24296a196a4..e65bcb093ae 100644 --- a/src/shared/proparser/proitems.cpp +++ b/src/shared/proparser/proitems.cpp @@ -194,6 +194,29 @@ ProString &ProString::prepend(const ProString &other) return *this; } +ProString &ProString::append(const QLatin1String other) +{ + const char *latin1 = other.latin1(); +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) + int size = other.size(); +#else + int size = strlen(latin1); +#endif + if (size) { + QChar *ptr = prepareExtend(size, 0, m_length); + for (int i = 0; i < size; i++) + *ptr++ = QLatin1Char(latin1[i]); + } + return *this; +} + +ProString &ProString::append(QChar other) +{ + QChar *ptr = prepareExtend(1, 0, m_length); + *ptr = other; + return *this; +} + // If pending != 0, prefix with space if appending to non-empty non-pending ProString &ProString::append(const ProString &other, bool *pending) { diff --git a/src/shared/proparser/proitems.h b/src/shared/proparser/proitems.h index db850d173f5..4e95beaeea7 100644 --- a/src/shared/proparser/proitems.h +++ b/src/shared/proparser/proitems.h @@ -79,9 +79,17 @@ public: 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 QString &other) { return append(ProString(other)); } + ProString &append(const QLatin1String other); + ProString &append(const char *other) { return append(QLatin1String(other)); } + ProString &append(QChar other); ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false); + ProString &operator+=(const ProString &other) { return append(other); } + ProString &operator+=(const QString &other) { return append(other); } + ProString &operator+=(const QLatin1String other) { return append(other); } + ProString &operator+=(const char *other) { return append(other); } + ProString &operator+=(QChar other) { return append(other); } void chop(int n) { Q_ASSERT(n <= m_length); m_length -= n; } void chopFront(int n) { Q_ASSERT(n <= m_length); m_offset += n; m_length -= n; }