init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
66
Telegram/lib_base/base/qt/qt_string_view.h
Normal file
66
Telegram/lib_base/base/qt/qt_string_view.h
Normal file
@@ -0,0 +1,66 @@
|
||||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QString>
|
||||
|
||||
namespace base {
|
||||
namespace details {
|
||||
|
||||
struct ContainerImplHelper {
|
||||
enum CutResult { Null, Empty, Full, Subset };
|
||||
static constexpr CutResult mid(
|
||||
qsizetype originalLength,
|
||||
qsizetype *_position,
|
||||
qsizetype *_length) {
|
||||
qsizetype &position = *_position;
|
||||
qsizetype &length = *_length;
|
||||
if (position > originalLength) {
|
||||
position = 0;
|
||||
length = 0;
|
||||
return Null;
|
||||
}
|
||||
|
||||
if (position < 0) {
|
||||
if (length < 0 || length + position >= originalLength) {
|
||||
position = 0;
|
||||
length = originalLength;
|
||||
return Full;
|
||||
}
|
||||
if (length + position <= 0) {
|
||||
position = length = 0;
|
||||
return Null;
|
||||
}
|
||||
length += position;
|
||||
position = 0;
|
||||
} else if (size_t(length) > size_t(originalLength - position)) {
|
||||
length = originalLength - position;
|
||||
}
|
||||
|
||||
if (position == 0 && length == originalLength)
|
||||
return Full;
|
||||
|
||||
return length > 0 ? Subset : Empty;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace details
|
||||
|
||||
[[nodiscard]] inline QStringView StringViewMid(
|
||||
QStringView view,
|
||||
qsizetype pos,
|
||||
qsizetype n = -1) {
|
||||
const auto result = details::ContainerImplHelper::mid(
|
||||
view.size(),
|
||||
&pos,
|
||||
&n);
|
||||
return (result == details::ContainerImplHelper::Null)
|
||||
? QStringView()
|
||||
: view.mid(pos, n);
|
||||
}
|
||||
|
||||
} // namespace base
|
||||
Reference in New Issue
Block a user