Pass string views by value
string_view should always be passed by value; This commit is a sed
replace of the code to make all string_views pass by value, per general
coding guidelines[1].
[1] https://quuxplusone.github.io/blog/2021/11/09/pass-string-view-by-value/
Tested: Code compiles.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I55b342a29a0fbfce0a4ed9ea63db6014d03b134c
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index cf3ddc2..8f2478f 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -109,7 +109,7 @@
return type == allowed;
}
-inline std::string urlEncode(const std::string_view value)
+inline std::string urlEncode(std::string_view value)
{
std::ostringstream escaped;
escaped.fill('0');
diff --git a/include/human_sort.hpp b/include/human_sort.hpp
index f4dfbe0..7ab326d 100644
--- a/include/human_sort.hpp
+++ b/include/human_sort.hpp
@@ -22,8 +22,7 @@
} // namespace details
-inline int alphanumComp(const std::string_view left,
- const std::string_view right)
+inline int alphanumComp(std::string_view left, std::string_view right)
{
std::string_view::const_iterator l = left.begin();
diff --git a/include/ibm/utils.hpp b/include/ibm/utils.hpp
index 256cbc5..bb439ee 100644
--- a/include/ibm/utils.hpp
+++ b/include/ibm/utils.hpp
@@ -10,7 +10,7 @@
namespace ibm_utils
{
-inline bool createDirectory(const std::string_view path)
+inline bool createDirectory(std::string_view path)
{
// Create persistent directory
std::error_code ec;
diff --git a/include/nbd_proxy.hpp b/include/nbd_proxy.hpp
index 3472c3a..500ea76 100644
--- a/include/nbd_proxy.hpp
+++ b/include/nbd_proxy.hpp
@@ -109,7 +109,7 @@
"xyz.openbmc_project.VirtualMedia.Proxy", "Mount");
}
- void send(const std::string_view data)
+ void send(std::string_view data)
{
boost::asio::buffer_copy(ws2uxBuf.prepare(data.size()),
boost::asio::buffer(data));
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 9bf968a..3035105 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -108,8 +108,7 @@
inline void setErrorResponse(crow::Response& res,
boost::beast::http::status result,
- const std::string& desc,
- const std::string_view msg)
+ const std::string& desc, std::string_view msg)
{
res.result(result);
res.jsonValue["data"]["description"] = desc;
diff --git a/include/pam_authenticate.hpp b/include/pam_authenticate.hpp
index ca8c8d3..5802078 100644
--- a/include/pam_authenticate.hpp
+++ b/include/pam_authenticate.hpp
@@ -83,8 +83,8 @@
* @param username The provided username aka account name.
* @param password The provided password.
* @returns PAM error code or PAM_SUCCESS for success. */
-inline int pamAuthenticateUser(const std::string_view username,
- const std::string_view password)
+inline int pamAuthenticateUser(std::string_view username,
+ std::string_view password)
{
std::string userStr(username);
std::string passStr(password);
diff --git a/include/security_headers.hpp b/include/security_headers.hpp
index d724de4..9877bb0 100644
--- a/include/security_headers.hpp
+++ b/include/security_headers.hpp
@@ -58,7 +58,7 @@
"object-src *; "
"base-uri *");
- const std::string_view origin = req.getHeaderValue("Origin");
+ std::string_view origin = req.getHeaderValue("Origin");
res.addHeader(bf::access_control_allow_origin, origin);
res.addHeader(bf::access_control_allow_methods, "GET, "
"POST, "
diff --git a/include/sessions.hpp b/include/sessions.hpp
index 19a1793..9795719 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -201,8 +201,7 @@
{
public:
std::shared_ptr<UserSession> generateUserSession(
- const std::string_view username,
- const boost::asio::ip::address& clientIp,
+ std::string_view username, const boost::asio::ip::address& clientIp,
const std::optional<std::string>& clientId,
PersistenceType persistence = PersistenceType::TIMEOUT,
bool isConfigureSelfOnly = false)
@@ -264,8 +263,7 @@
return it.first->second;
}
- std::shared_ptr<UserSession>
- loginSessionByToken(const std::string_view token)
+ std::shared_ptr<UserSession> loginSessionByToken(std::string_view token)
{
applySessionTimeouts();
if (token.size() != sessionTokenSize)
@@ -282,7 +280,7 @@
return userSession;
}
- std::shared_ptr<UserSession> getSessionByUid(const std::string_view uid)
+ std::shared_ptr<UserSession> getSessionByUid(std::string_view uid)
{
applySessionTimeouts();
// TODO(Ed) this is inefficient