Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/controller/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CommandType::CommandType(const QString& cmdName)
}
}

CommandType::operator std::string() const
CommandType::operator std::string_view() const
{
return QMetaEnum::fromType<CommandType::CommandTypeEnum>().valueToKey(value);
}
2 changes: 1 addition & 1 deletion src/controller/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CommandType
constexpr bool operator==(CommandTypeEnum other) const noexcept { return value == other; }
constexpr operator CommandTypeEnum() const noexcept { return value; }

operator std::string() const;
operator std::string_view() const;

private:
CommandTypeEnum value;
Expand Down
8 changes: 4 additions & 4 deletions src/controller/writeresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
namespace
{

QByteArray resultToJson(const QVariantMap& result, const std::string& commandType)
QByteArray resultToJson(const QVariantMap& result, std::string_view commandType)
{
const auto json = QJsonDocument::fromVariant(result);
if (!json.isObject()) {
throw std::logic_error("Controller::resultToJson: command " + commandType
throw std::logic_error("Controller::resultToJson: command " + std::string(commandType)
+ " did not return a JSON object");
}

Expand All @@ -27,15 +27,15 @@ QByteArray resultToJson(const QVariantMap& result, const std::string& commandTyp
} // namespace

void writeResponseToStdOut(bool isInStdinMode, const QVariantMap& result,
const std::string& commandType)
std::string_view commandType)
{
const auto response = resultToJson(result, commandType);

if (isInStdinMode) {
writeResponseLength(std::cout, uint32_t(response.size()));
}

std::cout << response.toStdString();
std::cout.write(response.constData(), std::streamsize(response.size()));

if (isInStdinMode) {
std::cout.flush(); // Don't write extra newline in stdin/stdout mode.
Expand Down
5 changes: 3 additions & 2 deletions src/controller/writeresponse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#pragma once

#include <QVariantMap>
#include <string>

#include <string_view>

void writeResponseToStdOut(bool isInStdinMode, const QVariantMap& result,
const std::string& commandType);
std::string_view commandType);
7 changes: 5 additions & 2 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ void WebEidDialog::onMultipleCertificatesReady(
});
ui->pageStack->setCurrentIndex(int(Page::SELECT_CERTIFICATE));
break;
default:
emit failure("Command %1 not allowed here"_L1.arg(QString::fromStdString(currentCommand)));
default: {
const std::string_view command = currentCommand;
emit failure("Command %1 not allowed here"_L1.arg(
QLatin1String(command.data(), qsizetype(command.size()))));
}
}
}

Expand Down