From 4403585a7075b1b06fd75a8ea31eb3bbf9101545 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 6 Jun 2020 13:29:12 +0200 Subject: [PATCH] Use the new C++20 starts_with() and contains() --- src/plugin/utils.cpp | 11 ++++++----- src/wine-host/bridges/group.cpp | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/plugin/utils.cpp b/src/plugin/utils.cpp index 581482b6..350a7544 100644 --- a/src/plugin/utils.cpp +++ b/src/plugin/utils.cpp @@ -44,8 +44,9 @@ std::string create_logger_prefix(const fs::path& socket_path) { // part since that's redundant std::string socket_name = socket_path.filename().replace_extension().string(); - const std::string socket_prefix("yabridge-"); - assert(socket_name.find(socket_prefix) == 0); + + constexpr std::string_view socket_prefix("yabridge-"); + assert(socket_name.starts_with(socket_prefix)); socket_name = socket_name.substr(socket_prefix.size()); std::ostringstream prefix; @@ -229,7 +230,7 @@ fs::path get_this_file_location() { // leading slash and then normalize the path, since three or more // slashes will be coerced into a single slash. fs::path this_file = boost::dll::this_line_location(); - if (this_file.string().find("//") == 0) { + if (this_file.string().starts_with("//")) { this_file = ("/" / this_file).lexically_normal(); } @@ -261,8 +262,8 @@ std::string get_wine_version() { // Strip the `wine-` prefix from the output, could potentially be absent in // custom Wine builds - const std::string version_prefix("wine-"); - if (version_string.find(version_prefix) == 0) { + constexpr std::string_view version_prefix("wine-"); + if (version_string.starts_with(version_prefix)) { version_string = version_string.substr(version_prefix.size()); } diff --git a/src/wine-host/bridges/group.cpp b/src/wine-host/bridges/group.cpp index 0e1e2bc7..503e8682 100644 --- a/src/wine-host/bridges/group.cpp +++ b/src/wine-host/bridges/group.cpp @@ -203,7 +203,7 @@ void GroupBridge::accept_requests() { // Collisions in the generated socket names should be very rare, but // it could in theory happen - assert(active_plugins.find(request) == active_plugins.end()); + assert(!active_plugins.contains(request)); // The plugin has to be initiated on the IO context's thread because // this has to be done on the same thread that's handling messages,