8#include <qstringlist.h>
9#include <qtextstream.h>
10#include <private/qduplicatetracker_p.h>
15size_t ProString::hash(
const QChar *p,
int n)
20 h = (h << 4) + (*p++).unicode();
21 h ^= (h & 0xf0000000) >> 23;
28 m_offset(0), m_length(0), m_file(0),
m_hash(0x80000000)
38 m_string(other.m_string), m_offset(other.m_offset), m_length(other.m_length), m_file(other.m_file), m_hash(0x80000000)
42ProString::ProString(
const QString &str, DoPreHashing) :
43 m_string(str), m_offset(0), m_length(str.size()), m_file(0)
58ProString::ProString(
const char *str, DoPreHashing) :
59 m_string(QString::fromLatin1(str)), m_offset(0), m_length(
int(qstrlen(str))), m_file(0)
69ProString::ProString(
const QString &str,
int offset,
int length, DoPreHashing) :
70 m_string(str), m_offset(offset), m_length(length), m_file(0)
75ProString::ProString(
const QString &str,
int offset,
int length, uint hash) :
76 m_string(str), m_offset(offset), m_length(length), m_file(0), m_hash(hash)
87 m_string = str, m_offset = 0, m_length = str.size(), m_hash = 0x80000000;
92 return (m_hash = hash(m_string.constData() + m_offset, m_length));
97 if (!(str.m_hash & 0x80000000))
99 return str.updatedHash();
124 m_string = str, m_offset = 0, m_length = str.size();
130 return m_string.mid(m_offset, m_length);
135 tmp = m_string.mid(m_offset, m_length);
141 if (other.m_length) {
145 m_string = other.toQStringView() + toQStringView();
147 m_length = m_string.size();
149 m_file = other.m_file;
159 if (m_length != m_string.size()) {
160 m_string = toQStringView() + other;
162 m_length = m_string.size();
164 Q_ASSERT(m_offset == 0);
165 m_string.append(other);
166 m_length += other.size();
175 if (m_length != m_string.size()) {
176 m_string = toQStringView() + other;
178 m_length = m_string.size();
180 Q_ASSERT(m_offset == 0);
181 m_string.append(other);
191 if (other.m_length) {
195 if (m_length != m_string.size())
196 m_string = toQString();
197 if (pending && !*pending) {
198 m_string += QLatin1Char(
' ') + other.toQStringView();
200 m_string += other.toQStringView();
202 m_length = m_string.size();
205 m_file = other.m_file;
216 if (
const int sz = other.size()) {
218 if (pending && !*pending && skipEmpty1st && other.at(0).isEmpty()) {
223 if (!m_length && sz == startIdx + 1) {
224 *
this = other.at(startIdx);
226 bool putSpace =
false;
227 if (pending && !*pending && m_length)
230 m_string = toQString();
232 for (
int i = startIdx; i < sz; ++i) {
234 m_string += QLatin1Char(
' ');
238 m_string += str.toQStringView();
240 m_length = m_string.size();
241 if (other.last().m_file)
242 m_file = other.last().m_file;
257 QString neu(one.m_length + two.m_length, Qt::Uninitialized);
258 ushort *ptr = (ushort *)neu.constData();
259 memcpy(ptr, one.m_string.constData() + one.m_offset, one.m_length * 2);
260 memcpy(ptr + one.m_length, two.m_string.constData() + two.m_offset, two.m_length * 2);
275 if ((uint)ret.m_length > (uint)len)
284 int end = cur + m_length;
285 const QChar *data = m_string.constData();
286 for (; cur < end; cur++)
287 if (!data[cur].isSpace()) {
289 while (data[end - 1].isSpace())
294 ret.m_length = end - cur;
298QTextStream &operator<<(QTextStream &t,
const ProString &str)
300 t << str.toQStringView();
307 const int sz = this_.size();
309 for (
int i = 0; i < sz; ++i)
310 totalLength += this_.at(i).size();
313 totalLength += sepSize * (sz - 1);
315 QString res(totalLength, Qt::Uninitialized);
316 QChar *ptr = (QChar *)res.constData();
317 for (
int i = 0; i < sz; ++i) {
319 memcpy(ptr, sep, sepSize *
sizeof(QChar));
323 memcpy(ptr, str.constData(), str.size() *
sizeof(QChar));
331 return ProStringList_join(*
this, sep.constData(), sep.size());
336 return ProStringList_join(*
this, sep.constData(), sep.size());
341 return ProStringList_join(*
this, &sep, 1);
346 for (
int i = size(); --i >= 0; )
353 for (
int i = size(); --i >= 0; )
360 for (
const ProString &str : value) {
370 for (
int i = size(); --i >= 0;)
377 QDuplicateTracker<ProString> seen(size());
378 removeIf([&](
const ProString &s) {
return seen.hasSeen(s); });
383 for (
const ProString &str : value)
384 if (!str.isEmpty() && !contains(str))
390 reserve(list.size());
391 for (
const QString &str : list)
392 *
this << ProString(str);
399 for (
const auto &e : *
this)
400 ret.append(e.toQString());
406 for (
int i = 0; i < size(); i++)
407 if (!at(i).compare(str, cs))
414 for (
int i = 0; i < size(); i++)
415 if (!at(i).toQStringView().compare(str, cs))
422 for (
int i = 0; i < size(); i++)
423 if (!at(i).compare(str, cs))
435 if (!fileName.startsWith(QLatin1Char(
'(')))
436 m_directoryName = QFileInfo(
437 fileName.left(fileName.lastIndexOf(QLatin1Char(
'/')))).canonicalFilePath();
456 hash |= (uint)*tPtr++ << 16;
ProFile(int id, const QString &fileName)
const ushort * tokPtr() const
ProString getStr(const ushort *&tPtr)
const QString & items() const
ProKey getHashStr(const ushort *&tPtr)
ProItemRefCount(int cnt=0)
void setValue(const QString &str)
ProKey(const QString &str, int off, int len, uint hash)
ProKey(const QString &str)
PROITEM_EXPLICIT ProKey(const char *str)
ProKey(const QString &str, int off, int len)
void removeAll(const ProString &str)
QString join(QChar sep) const
QString join(const ProString &sep) const
bool contains(const char *str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
void removeAll(const char *str)
void insertUnique(const ProStringList &value)
QString join(const QString &sep) const
bool contains(QStringView str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
void removeEach(const ProStringList &value)
ProStringList(const QStringList &list)
bool contains(const ProString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QStringList toQStringList() const
QString & toQString(QString &tmp) const
ProString & operator=(const ProString &)=default
friend size_t qHash(const ProString &str)
ProString & append(QChar other)
ProString mid(int off, int len=-1) const
QString toQString() const
ProString(const QString &str)
ProString & append(const QLatin1String other)
void setValue(const QString &str)
ProString(const QString &str, int offset, int length)
ProString & prepend(const ProString &other)
PROITEM_EXPLICIT ProString(QStringView str)
friend QString operator+(const ProString &one, const ProString &two)
ProString trimmed() const
ProString & append(const ProString &other, bool *pending=nullptr)
PROITEM_EXPLICIT ProString(const char *str)
ProString & setSource(int id)
ProString & append(const ProStringList &other, bool *pending=nullptr, bool skipEmpty1st=false)
ProString(const ProString &other)
Combined button and popup list for selecting options.
static QString ProStringList_join(const ProStringList &this_, const QChar *sep, const int sepSize)
QDebug operator<<(QDebug debug, const ProString &str)