FakeVim: Use QStringView instead of QStringRef

QStringRef will not exist in Qt 6.

Change-Id: I439240fbb4c87fbe71c9fa42596c9aaadb75a05e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2020-06-15 17:47:04 +02:00
parent a0764603d0
commit da829f3fe7

View File

@@ -1352,7 +1352,7 @@ class History
public: public:
History() : m_items(QString()) {} History() : m_items(QString()) {}
void append(const QString &item); void append(const QString &item);
const QString &move(const QStringRef &prefix, int skip); const QString &move(QStringView prefix, int skip);
const QString &current() const { return m_items[m_index]; } const QString &current() const { return m_items[m_index]; }
const QStringList &items() const { return m_items; } const QStringList &items() const { return m_items; }
void restart() { m_index = m_items.size() - 1; } void restart() { m_index = m_items.size() - 1; }
@@ -1373,7 +1373,7 @@ void History::append(const QString &item)
restart(); restart();
} }
const QString &History::move(const QStringRef &prefix, int skip) const QString &History::move(QStringView prefix, int skip)
{ {
if (!current().startsWith(prefix)) if (!current().startsWith(prefix))
restart(); restart();
@@ -1403,7 +1403,7 @@ public:
m_buffer = s; m_pos = m_userPos = pos; m_anchor = anchor >= 0 ? anchor : pos; m_buffer = s; m_pos = m_userPos = pos; m_anchor = anchor >= 0 ? anchor : pos;
} }
QStringRef userContents() const { return m_buffer.leftRef(m_userPos); } QStringView userContents() const { return QStringView{m_buffer}.left(m_userPos); }
const QChar &prompt() const { return m_prompt; } const QChar &prompt() const { return m_prompt; }
const QString &contents() const { return m_buffer; } const QString &contents() const { return m_buffer; }
bool isEmpty() const { return m_buffer.isEmpty(); } bool isEmpty() const { return m_buffer.isEmpty(); }
@@ -1424,8 +1424,9 @@ public:
void moveEnd() { m_userPos = m_pos = m_buffer.size(); } void moveEnd() { m_userPos = m_pos = m_buffer.size(); }
void setHistoryAutoSave(bool autoSave) { m_historyAutoSave = autoSave; } void setHistoryAutoSave(bool autoSave) { m_historyAutoSave = autoSave; }
void historyDown() { setContents(m_history.move(userContents(), 1)); } bool userContentsValid() const { return m_userPos >= 0 && m_userPos <= m_buffer.size(); }
void historyUp() { setContents(m_history.move(userContents(), -1)); } void historyDown() { if (userContentsValid()) setContents(m_history.move(userContents(), 1)); }
void historyUp() { if (userContentsValid()) setContents(m_history.move(userContents(), -1)); }
const QStringList &historyItems() const { return m_history.items(); } const QStringList &historyItems() const { return m_history.items(); }
void historyPush(const QString &item = QString()) void historyPush(const QString &item = QString())
{ {