chore: use string_view in place of string where possible
This commit is contained in:
parent
fe12972e83
commit
5a90b51e97
20 changed files with 40 additions and 39 deletions
|
|
@ -162,7 +162,7 @@ bool CaselessCmp::operator()(const std::string &a, const std::string &b) const
|
|||
return less(a, b);
|
||||
}
|
||||
|
||||
bool CaselessCmp::less(const std::string &a, const std::string &b)
|
||||
bool CaselessCmp::less(const std::string_view &a, const std::string_view &b)
|
||||
{
|
||||
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), &deskflow::string::CaselessCmp::cmpLess);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public:
|
|||
bool operator()(const std::string &a, const std::string &b) const;
|
||||
|
||||
//! Returns true iff \c a is lexicographically less than \c b
|
||||
static bool less(const std::string &a, const std::string &b);
|
||||
static bool less(const std::string_view &a, const std::string_view &b);
|
||||
|
||||
//! Returns true iff \c a is lexicographically equal to \c b
|
||||
static bool equal(const std::string &a, const std::string &b);
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ std::string Unicode::UCS2ToUTF8(const std::string &src, bool *errors)
|
|||
return doUCS2ToUTF8(reinterpret_cast<const uint8_t *>(src.data()), n, errors);
|
||||
}
|
||||
|
||||
std::string Unicode::UCS4ToUTF8(const std::string &src, bool *errors)
|
||||
std::string Unicode::UCS4ToUTF8(const std::string_view &src, bool *errors)
|
||||
{
|
||||
// default to success
|
||||
resetError(errors);
|
||||
|
|
@ -236,7 +236,7 @@ std::string Unicode::UCS4ToUTF8(const std::string &src, bool *errors)
|
|||
return doUCS4ToUTF8(reinterpret_cast<const uint8_t *>(src.data()), n, errors);
|
||||
}
|
||||
|
||||
std::string Unicode::UTF16ToUTF8(const std::string &src, bool *errors)
|
||||
std::string Unicode::UTF16ToUTF8(const std::string_view &src, bool *errors)
|
||||
{
|
||||
// default to success
|
||||
resetError(errors);
|
||||
|
|
@ -246,7 +246,7 @@ std::string Unicode::UTF16ToUTF8(const std::string &src, bool *errors)
|
|||
return doUTF16ToUTF8(reinterpret_cast<const uint8_t *>(src.data()), n, errors);
|
||||
}
|
||||
|
||||
std::string Unicode::UTF32ToUTF8(const std::string &src, bool *errors)
|
||||
std::string Unicode::UTF32ToUTF8(const std::string_view &src, bool *errors)
|
||||
{
|
||||
// default to success
|
||||
resetError(errors);
|
||||
|
|
|
|||
|
|
@ -81,21 +81,21 @@ public:
|
|||
Convert from UCS-4 to UTF-8. If errors is not nullptr then *errors is
|
||||
set to true iff any character could not be decoded.
|
||||
*/
|
||||
static std::string UCS4ToUTF8(const std::string &, bool *errors = nullptr);
|
||||
static std::string UCS4ToUTF8(const std::string_view &, bool *errors = nullptr);
|
||||
|
||||
//! Convert from UTF-16 to UTF-8
|
||||
/*!
|
||||
Convert from UTF-16 to UTF-8. If errors is not nullptr then *errors is
|
||||
set to true iff any character could not be decoded.
|
||||
*/
|
||||
static std::string UTF16ToUTF8(const std::string &, bool *errors = nullptr);
|
||||
static std::string UTF16ToUTF8(const std::string_view &, bool *errors = nullptr);
|
||||
|
||||
//! Convert from UTF-32 to UTF-8
|
||||
/*!
|
||||
Convert from UTF-32 to UTF-8. If errors is not nullptr then *errors is
|
||||
set to true iff any character could not be decoded.
|
||||
*/
|
||||
static std::string UTF32ToUTF8(const std::string &, bool *errors = nullptr);
|
||||
static std::string UTF32ToUTF8(const std::string_view &, bool *errors = nullptr);
|
||||
|
||||
//! Convert from the current locale encoding to UTF-8
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ bool ArgParser::isArg(
|
|||
return false;
|
||||
}
|
||||
|
||||
void ArgParser::splitCommandString(const std::string &command, std::vector<std::string> &argv)
|
||||
void ArgParser::splitCommandString(const std::string_view &command, std::vector<std::string> &argv)
|
||||
{
|
||||
if (command.empty()) {
|
||||
return;
|
||||
|
|
@ -256,10 +256,10 @@ void ArgParser::splitCommandString(const std::string &command, std::vector<std::
|
|||
}
|
||||
|
||||
if (!ignoreThisSpace) {
|
||||
std::string subString = command.substr(startPos, space - startPos);
|
||||
auto subString = command.substr(startPos, space - startPos);
|
||||
|
||||
removeDoubleQuotes(subString);
|
||||
argv.push_back(subString);
|
||||
argv.push_back(std::string{subString.begin(), subString.end()});
|
||||
}
|
||||
|
||||
// find next space
|
||||
|
|
@ -271,12 +271,12 @@ void ArgParser::splitCommandString(const std::string &command, std::vector<std::
|
|||
}
|
||||
}
|
||||
|
||||
std::string subString = command.substr(startPos, command.size());
|
||||
auto subString = command.substr(startPos, command.size());
|
||||
removeDoubleQuotes(subString);
|
||||
argv.push_back(subString);
|
||||
argv.push_back(std::string{subString.begin(), subString.end()});
|
||||
}
|
||||
|
||||
bool ArgParser::searchDoubleQuotes(const std::string &command, size_t &left, size_t &right, size_t startPos)
|
||||
bool ArgParser::searchDoubleQuotes(const std::string_view &command, size_t &left, size_t &right, size_t startPos)
|
||||
{
|
||||
bool result = false;
|
||||
left = std::string::npos;
|
||||
|
|
@ -298,7 +298,7 @@ bool ArgParser::searchDoubleQuotes(const std::string &command, size_t &left, siz
|
|||
return result;
|
||||
}
|
||||
|
||||
void ArgParser::removeDoubleQuotes(std::string &arg)
|
||||
void ArgParser::removeDoubleQuotes(std::string_view &arg)
|
||||
{
|
||||
// if string is surrounded by double quotes, remove them
|
||||
if (arg[0] == '\"' && arg[arg.size() - 1] == '\"') {
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ public:
|
|||
static bool isArg(
|
||||
int argi, int argc, const char *const *argv, const char *name1, const char *name2, int minRequiredParameters = 0
|
||||
);
|
||||
static void splitCommandString(const std::string &command, std::vector<std::string> &argv);
|
||||
static bool searchDoubleQuotes(const std::string &command, size_t &left, size_t &right, size_t startPos = 0);
|
||||
static void removeDoubleQuotes(std::string &arg);
|
||||
static void splitCommandString(const std::string_view &command, std::vector<std::string> &argv);
|
||||
static bool searchDoubleQuotes(const std::string_view &command, size_t &left, size_t &right, size_t startPos = 0);
|
||||
static void removeDoubleQuotes(std::string_view &arg);
|
||||
static const char **getArgv(std::vector<std::string> &argsArray);
|
||||
static std::string
|
||||
assembleCommand(std::vector<std::string> &argsArray, std::string ignoreArg = "", int parametersRequired = 0);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
// IClipboard
|
||||
//
|
||||
|
||||
void IClipboard::unmarshall(IClipboard *clipboard, const std::string &data, Time time)
|
||||
void IClipboard::unmarshall(IClipboard *clipboard, const std::string_view &data, Time time)
|
||||
{
|
||||
assert(clipboard != nullptr);
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ public:
|
|||
Extract marshalled clipboard data and store it in \p clipboard.
|
||||
Sets the clipboard time to \c time.
|
||||
*/
|
||||
static void unmarshall(IClipboard *clipboard, const std::string &data, Time time);
|
||||
static void unmarshall(IClipboard *clipboard, const std::string_view &data, Time time);
|
||||
|
||||
//! Copy clipboard
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ bool IKeyState::KeyInfo::isDefault(const char *screens)
|
|||
return (screens == nullptr || screens[0] == '\0');
|
||||
}
|
||||
|
||||
bool IKeyState::KeyInfo::contains(const char *screens, const std::string &name)
|
||||
bool IKeyState::KeyInfo::contains(const char *screens, const std::string_view &name)
|
||||
{
|
||||
// special cases
|
||||
if (isDefault(screens)) {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public:
|
|||
static KeyInfo *alloc(const KeyInfo &);
|
||||
|
||||
static bool isDefault(const char *screens);
|
||||
static bool contains(const char *screens, const std::string &name);
|
||||
static bool contains(const char *screens, const std::string_view &name);
|
||||
static bool equal(const KeyInfo *, const KeyInfo *);
|
||||
static std::string join(const std::set<std::string> &destinations);
|
||||
static void split(const char *screens, std::set<std::string> &);
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ void ServerApp::updateStatus()
|
|||
updateStatus("");
|
||||
}
|
||||
|
||||
void ServerApp::updateStatus(const std::string &msg) const
|
||||
void ServerApp::updateStatus(const std::string_view &msg) const
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public:
|
|||
void closeServer(Server *server);
|
||||
void stopRetryTimer();
|
||||
void updateStatus();
|
||||
void updateStatus(const std::string &msg) const;
|
||||
void updateStatus(const std::string_view &msg) const;
|
||||
void closeClientListener(ClientListener *listen);
|
||||
void stopServer();
|
||||
void closePrimaryClient(PrimaryClient *primaryClient);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ using namespace std;
|
|||
static const size_t g_chunkSize = 512 * 1024; // 512kb
|
||||
|
||||
void StreamChunker::sendClipboard(
|
||||
const std::string &data, size_t size, ClipboardID id, uint32_t sequence, IEventQueue *events, void *eventTarget
|
||||
const std::string_view &data, size_t size, ClipboardID id, uint32_t sequence, IEventQueue *events, void *eventTarget
|
||||
)
|
||||
{
|
||||
// send first message (data size)
|
||||
|
|
@ -42,7 +42,7 @@ void StreamChunker::sendClipboard(
|
|||
chunkSize = size - sentLength;
|
||||
}
|
||||
|
||||
std::string chunk(data.substr(sentLength, chunkSize).c_str(), chunkSize);
|
||||
std::string chunk(data.substr(sentLength, chunkSize).data(), chunkSize);
|
||||
ClipboardChunk *dataChunk = ClipboardChunk::data(id, sequence, chunk);
|
||||
|
||||
events->addEvent(Event(EventTypes::ClipboardSending, eventTarget, dataChunk));
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace {
|
||||
|
||||
std::string vectorToString(const std::vector<std::string> &vector, const std::string &delimiter = "")
|
||||
std::string vectorToString(const std::vector<std::string> &vector, const std::string_view &delimiter = "")
|
||||
{
|
||||
std::string string;
|
||||
for (const auto &item : vector) {
|
||||
|
|
@ -34,12 +34,13 @@ LanguageManager::LanguageManager(const std::vector<std::string> &localLanguages)
|
|||
LOG((CLOG_INFO "local languages: %s", vectorToString(m_localLanguages, ", ").c_str()));
|
||||
}
|
||||
|
||||
void LanguageManager::setRemoteLanguages(const std::string &remoteLanguages)
|
||||
void LanguageManager::setRemoteLanguages(const std::string_view &remoteLanguages)
|
||||
{
|
||||
m_remoteLanguages.clear();
|
||||
if (!remoteLanguages.empty()) {
|
||||
for (size_t i = 0; i <= remoteLanguages.size() - 2; i += 2) {
|
||||
m_remoteLanguages.push_back(remoteLanguages.substr(i, 2));
|
||||
auto rLangs = remoteLanguages.substr(i, 2);
|
||||
m_remoteLanguages.push_back(std::string{rLangs.begin(), rLangs.end()});
|
||||
}
|
||||
}
|
||||
LOG((CLOG_INFO "remote languages: %s", vectorToString(m_remoteLanguages, ", ").c_str()));
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public:
|
|||
* @brief setRemoteLanguages sets remote languages
|
||||
* @param remoteLanguages is a string with sericalized languages
|
||||
*/
|
||||
void setRemoteLanguages(const std::string &remoteLanguages);
|
||||
void setRemoteLanguages(const std::string_view &remoteLanguages);
|
||||
|
||||
/**
|
||||
* @brief getRemoteLanguages getter for remote languages
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ std::vector<X11LayoutsParser::Lang> X11LayoutsParser::getAllLanguageData(const s
|
|||
void X11LayoutsParser::appendVectorUniq(const std::vector<std::string> &source, std::vector<std::string> &dst)
|
||||
{
|
||||
for (const auto &elem : source) {
|
||||
if (std::find_if(dst.begin(), dst.end(), [elem](const std::string &s) { return s == elem; }) == dst.end()) {
|
||||
if (std::find_if(dst.begin(), dst.end(), [elem](const std::string_view &s) { return s == elem; }) == dst.end()) {
|
||||
dst.push_back(elem);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1147,7 +1147,7 @@ void Config::parseAction(
|
|||
rule.adoptAction(action, activate);
|
||||
}
|
||||
|
||||
void Config::parseScreens(const ConfigReadContext &c, const std::string &s, std::set<std::string> &screens) const
|
||||
void Config::parseScreens(const ConfigReadContext &c, const std::string_view &s, std::set<std::string> &screens) const
|
||||
{
|
||||
screens.clear();
|
||||
|
||||
|
|
@ -1370,7 +1370,7 @@ Config::CellEdge::CellEdge(const std::string &name, EDirection side, const Inter
|
|||
init(name, side, interval);
|
||||
}
|
||||
|
||||
void Config::CellEdge::init(const std::string &name, EDirection side, const Interval &interval)
|
||||
void Config::CellEdge::init(const std::string_view &name, EDirection side, const Interval &interval)
|
||||
{
|
||||
assert(side != kNoDirection);
|
||||
|
||||
|
|
@ -1384,7 +1384,7 @@ Config::Interval Config::CellEdge::getInterval() const
|
|||
return m_interval;
|
||||
}
|
||||
|
||||
void Config::CellEdge::setName(const std::string &newName)
|
||||
void Config::CellEdge::setName(const std::string_view &newName)
|
||||
{
|
||||
m_name = newName;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ public:
|
|||
~CellEdge() = default;
|
||||
|
||||
Interval getInterval() const;
|
||||
void setName(const std::string &newName);
|
||||
void setName(const std::string_view &newName);
|
||||
std::string getName() const;
|
||||
EDirection getSide() const;
|
||||
bool overlaps(const CellEdge &) const;
|
||||
|
|
@ -84,7 +84,7 @@ public:
|
|||
bool operator!=(const CellEdge &) const;
|
||||
|
||||
private:
|
||||
void init(const std::string &name, EDirection side, const Interval &);
|
||||
void init(const std::string_view &name, EDirection side, const Interval &);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
|
|
@ -474,7 +474,7 @@ private:
|
|||
bool activate
|
||||
);
|
||||
|
||||
void parseScreens(const ConfigReadContext &, const std::string &, std::set<std::string> &screens) const;
|
||||
void parseScreens(const ConfigReadContext &, const std::string_view &, std::set<std::string> &screens) const;
|
||||
static const char *getOptionName(OptionID);
|
||||
static std::string getOptionValue(OptionID, OptionValue);
|
||||
|
||||
|
|
|
|||
|
|
@ -845,7 +845,7 @@ void InputFilter::setPrimaryClient(PrimaryClient *client)
|
|||
}
|
||||
}
|
||||
|
||||
std::string InputFilter::format(const std::string &linePrefix) const
|
||||
std::string InputFilter::format(const std::string_view &linePrefix) const
|
||||
{
|
||||
std::string s;
|
||||
for (auto i = m_ruleList.begin(); i != m_ruleList.end(); ++i) {
|
||||
|
|
|
|||
|
|
@ -375,7 +375,7 @@ public:
|
|||
virtual void setPrimaryClient(PrimaryClient *client);
|
||||
|
||||
// convert rules to a string
|
||||
std::string format(const std::string &linePrefix) const;
|
||||
std::string format(const std::string_view &linePrefix) const;
|
||||
|
||||
// get number of rules
|
||||
uint32_t getNumRules() const;
|
||||
|
|
|
|||
Loading…
Reference in a new issue