diff options
author | Ed Tanous <edtanous@google.com> | 2022-07-11 19:50:41 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2022-07-16 05:03:56 +0300 |
commit | 11ba39793c016e8476e44be880fb267e059dd4eb (patch) | |
tree | 863b07c67ed699cf051ed792b01f68c82027c94c /include | |
parent | 433b68b477a82a31de4104a83404021de1f30214 (diff) | |
download | bmcweb-11ba39793c016e8476e44be880fb267e059dd4eb.tar.xz |
Remove usages of boost::starts/ends_with
Per the coding standard, now that C++ supports std::string::starts_with
and std::string::ends_with, we should be using them over the boost
alternatives. This commit goes through and updates all usages.
Arguably some of these are incorrect, and instances of common error 13,
but because this is mostly a mechanical it intentionally doesn't try to
handle it.
Tested: Unit tests pass.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ic4c6e5d0da90f7442693199dc691a47d2240fa4f
Diffstat (limited to 'include')
-rw-r--r-- | include/authentication.hpp | 5 | ||||
-rw-r--r-- | include/http_utility.hpp | 3 | ||||
-rw-r--r-- | include/ibm/locks.hpp | 3 | ||||
-rw-r--r-- | include/ibm/management_console_rest.hpp | 2 | ||||
-rw-r--r-- | include/login_routes.hpp | 4 | ||||
-rw-r--r-- | include/multipart_parser.hpp | 4 | ||||
-rw-r--r-- | include/openbmc_dbus_rest.hpp | 35 | ||||
-rw-r--r-- | include/webassets.hpp | 4 |
8 files changed, 28 insertions, 32 deletions
diff --git a/include/authentication.hpp b/include/authentication.hpp index 8d59be406e..ac2a7d14a7 100644 --- a/include/authentication.hpp +++ b/include/authentication.hpp @@ -3,7 +3,6 @@ #include "webroutes.hpp" #include <app.hpp> -#include <boost/algorithm/string/predicate.hpp> #include <boost/container/flat_set.hpp> #include <common.hpp> #include <forward_unauthorized.hpp> @@ -42,7 +41,7 @@ static std::shared_ptr<persistent_data::UserSession> { BMCWEB_LOG_DEBUG << "[AuthMiddleware] Basic authentication"; - if (!boost::starts_with(authHeader, "Basic ")) + if (!authHeader.starts_with("Basic ")) { return nullptr; } @@ -97,7 +96,7 @@ static std::shared_ptr<persistent_data::UserSession> performTokenAuth(std::string_view authHeader) { BMCWEB_LOG_DEBUG << "[AuthMiddleware] Token authentication"; - if (!boost::starts_with(authHeader, "Token ")) + if (!authHeader.starts_with("Token ")) { return nullptr; } diff --git a/include/http_utility.hpp b/include/http_utility.hpp index 3970992974..c150943f8f 100644 --- a/include/http_utility.hpp +++ b/include/http_utility.hpp @@ -1,7 +1,8 @@ #pragma once #include "http_request.hpp" -#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <boost/algorithm/string/split.hpp> namespace http_helpers { diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp index 2c6668c9a6..5df3daa975 100644 --- a/include/ibm/locks.hpp +++ b/include/ibm/locks.hpp @@ -1,6 +1,6 @@ #pragma once -#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/predicate.hpp> #include <boost/container/flat_map.hpp> #include <boost/endian/conversion.hpp> #include <include/ibm/utils.hpp> @@ -9,6 +9,7 @@ #include <filesystem> #include <fstream> +#include <variant> namespace crow { diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index 8d50c9f147..0d8e287802 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -2,7 +2,7 @@ #include <app.hpp> #include <async_resp.hpp> -#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/predicate.hpp> #include <boost/container/flat_set.hpp> #include <error_messages.hpp> #include <event_service_manager.hpp> diff --git a/include/login_routes.hpp b/include/login_routes.hpp index fde4b8f645..fd1c357d10 100644 --- a/include/login_routes.hpp +++ b/include/login_routes.hpp @@ -34,7 +34,7 @@ inline void requestRoutes(App& app) // within it are not destroyed before we can use them nlohmann::json loginCredentials; // Check if auth was provided by a payload - if (boost::starts_with(contentType, "application/json")) + if (contentType.starts_with("application/json")) { loginCredentials = nlohmann::json::parse(req.body, nullptr, false); if (loginCredentials.is_discarded()) @@ -116,7 +116,7 @@ inline void requestRoutes(App& app) } } } - else if (boost::starts_with(contentType, "multipart/form-data")) + else if (contentType.starts_with("multipart/form-data")) { looksLikePhosphorRest = true; MultipartParser parser; diff --git a/include/multipart_parser.hpp b/include/multipart_parser.hpp index 9d801da979..2fe3679452 100644 --- a/include/multipart_parser.hpp +++ b/include/multipart_parser.hpp @@ -1,6 +1,5 @@ #pragma once -#include <boost/algorithm/string/predicate.hpp> #include <boost/beast/http/fields.hpp> #include <http_request.hpp> @@ -58,8 +57,7 @@ class MultipartParser std::string_view contentType = req.getHeaderValue("content-type"); const std::string boundaryFormat = "multipart/form-data; boundary="; - if (!boost::starts_with(req.getHeaderValue("content-type"), - boundaryFormat)) + if (!contentType.starts_with(boundaryFormat)) { return ParserError::ERROR_BOUNDARY_FORMAT; } diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index d0bc29c3d1..cf07f76f33 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -17,7 +17,9 @@ #include <app.hpp> #include <async_resp.hpp> -#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/classification.hpp> +#include <boost/algorithm/string/predicate.hpp> +#include <boost/algorithm/string/split.hpp> #include <boost/container/flat_set.hpp> #include <dbus_singleton.hpp> #include <dbus_utility.hpp> @@ -207,7 +209,7 @@ inline void findRemainingObjectsForEnumerate( { for (const auto& interface : interfaces) { - if (!boost::starts_with(interface, "org.freedesktop.DBus")) + if (!interface.starts_with("org.freedesktop.DBus")) { getPropertiesForEnumerate(path, service, interface, asyncResp); @@ -244,7 +246,6 @@ struct InProgressEnumerateData InProgressEnumerateData(InProgressEnumerateData&&) = delete; InProgressEnumerateData& operator=(const InProgressEnumerateData&) = delete; InProgressEnumerateData& operator=(InProgressEnumerateData&&) = delete; - const std::string objectPath; std::shared_ptr<dbus::utility::MapperGetSubTreeResponse> subtree; std::shared_ptr<bmcweb::AsyncResp> asyncResp; @@ -275,7 +276,7 @@ inline void getManagedObjectsForEnumerate( for (const auto& objectPath : objects) { - if (boost::starts_with(objectPath.first.str, objectName)) + if (objectPath.first.str.starts_with(objectName)) { BMCWEB_LOG_DEBUG << "Reading object " << objectPath.first.str; nlohmann::json& objectJson = dataJson[objectPath.first.str]; @@ -775,7 +776,7 @@ inline int convertJsonToDbus(sd_bus_message* m, const std::string& argType, } sd_bus_message_append_basic(m, argCode[0], doubleValue); } - else if (boost::starts_with(argCode, "a")) + else if (argCode.starts_with("a")) { std::string containedType = argCode.substr(1); r = sd_bus_message_open_container(m, SD_BUS_TYPE_ARRAY, @@ -795,7 +796,7 @@ inline int convertJsonToDbus(sd_bus_message* m, const std::string& argType, } sd_bus_message_close_container(m); } - else if (boost::starts_with(argCode, "v")) + else if (argCode.starts_with("v")) { std::string containedType = argCode.substr(1); BMCWEB_LOG_DEBUG << "variant type: " << argCode @@ -819,8 +820,7 @@ inline int convertJsonToDbus(sd_bus_message* m, const std::string& argType, return r; } } - else if (boost::starts_with(argCode, "(") && - boost::ends_with(argCode, ")")) + else if (argCode.starts_with("(") && argCode.ends_with(")")) { std::string containedType = argCode.substr(1, argCode.size() - 1); r = sd_bus_message_open_container(m, SD_BUS_TYPE_STRUCT, @@ -846,8 +846,7 @@ inline int convertJsonToDbus(sd_bus_message* m, const std::string& argType, } r = sd_bus_message_close_container(m); } - else if (boost::starts_with(argCode, "{") && - boost::ends_with(argCode, "}")) + else if (argCode.starts_with("{") && argCode.ends_with("}")) { std::string containedType = argCode.substr(1, argCode.size() - 1); r = sd_bus_message_open_container(m, SD_BUS_TYPE_DICT_ENTRY, @@ -1000,8 +999,7 @@ inline int readArrayFromMessage(const std::string& typeCode, return r; } - bool dict = boost::starts_with(containedType, "{") && - boost::ends_with(containedType, "}"); + bool dict = containedType.starts_with("{") && containedType.ends_with("}"); if (dict) { @@ -1243,7 +1241,7 @@ inline int convertDBusToJSON(const std::string& returnType, return r; } } - else if (boost::starts_with(typeCode, "a")) + else if (typeCode.starts_with("a")) { r = readArrayFromMessage(typeCode, m, *thisElement); if (r < 0) @@ -1251,8 +1249,7 @@ inline int convertDBusToJSON(const std::string& returnType, return r; } } - else if (boost::starts_with(typeCode, "(") && - boost::ends_with(typeCode, ")")) + else if (typeCode.starts_with("(") && typeCode.ends_with(")")) { r = readStructFromMessage(typeCode, m, *thisElement); if (r < 0) @@ -1260,7 +1257,7 @@ inline int convertDBusToJSON(const std::string& returnType, return r; } } - else if (boost::starts_with(typeCode, "v")) + else if (typeCode.starts_with("v")) { r = readVariantFromMessage(m, *thisElement); if (r < 0) @@ -2028,13 +2025,13 @@ inline void handleDBusUrl(const crow::Request& req, } else if (req.method() == boost::beast::http::verb::get) { - if (boost::ends_with(objectPath, "/enumerate")) + if (objectPath.ends_with("/enumerate")) { objectPath.erase(objectPath.end() - sizeof("enumerate"), objectPath.end()); handleEnumerate(asyncResp, objectPath); } - else if (boost::ends_with(objectPath, "/list")) + else if (objectPath.ends_with("/list")) { objectPath.erase(objectPath.end() - sizeof("list"), objectPath.end()); @@ -2043,7 +2040,7 @@ inline void handleDBusUrl(const crow::Request& req, else { // Trim any trailing "/" at the end - if (boost::ends_with(objectPath, "/")) + if (objectPath.ends_with("/")) { objectPath.pop_back(); handleList(asyncResp, objectPath, 1); diff --git a/include/webassets.hpp b/include/webassets.hpp index 6353a42b1a..3d25296f4e 100644 --- a/include/webassets.hpp +++ b/include/webassets.hpp @@ -79,7 +79,7 @@ inline void requestRoutes(App& app) if (std::filesystem::is_directory(dir)) { // don't recurse into hidden directories or symlinks - if (boost::starts_with(dir.path().filename().string(), ".") || + if (dir.path().filename().string().starts_with(".") || std::filesystem::is_symlink(dir)) { dirIter.disable_recursion_pending(); @@ -99,7 +99,7 @@ inline void requestRoutes(App& app) contentEncoding = "gzip"; } - if (boost::starts_with(webpath.filename().string(), "index.")) + if (webpath.filename().string().starts_with("index.")) { webpath = webpath.parent_path(); if (webpath.string().empty() || webpath.string().back() != '/') |