Перепись с const std::string& на std::string_view

This commit is contained in:
2026-01-29 18:45:16 +03:00
parent 9a7c9b7e7c
commit 3f77cdc2bd
3 changed files with 8 additions and 9 deletions
+2 -2
View File
@@ -27,10 +27,10 @@
- Написать фронтенд для MVP - Написать фронтенд для MVP
- Разобрать decltype и auto по статье - Разобрать decltype и auto по статье
До 27.01.2026 До 27.01.2026
- Подобрать сервер по параметрам. Использовать linux. - ~~Подобрать сервер по параметрам. Использовать linux.~~ DockerHosting.ru
- Перевести string на string_view - Перевести string на string_view
- ~~Попробовать nodiscard к executoru~~ - ~~Попробовать nodiscard к executoru~~
- Добить 2 ручки - ~~Добить 2 ручки~~
- Сделать тесты для ручек - Сделать тесты для ручек
# План # План
@@ -97,16 +97,16 @@ public:
} }
private: private:
bool ValidateLogin(const std::string& login) bool ValidateLogin(std::string_view login)
{ {
if (login.size() < 3 || login.size() > 50) return false; if (login.size() < 3 || login.size() > 50) return false;
std::regex pattern(std::string("^[A-Za-z0-9_]+$")); std::regex pattern(std::string("^[A-Za-z0-9_]+$"));
return std::regex_match(login, pattern); return std::regex_match(login.data(), pattern);
} }
bool ValidatePassword(const std::string& password) bool ValidatePassword(std::string_view password)
{ {
return password.size() >= 5; return password.size() >= 5;
} }
+3 -4
View File
@@ -166,13 +166,12 @@ public:
{ {
namespace urls = boost::urls; namespace urls = boost::urls;
const std::string& route = req.target(); const bool is_match_route = routes_pathes_.count(req.target());
const bool is_match_route = routes_pathes_.count(route);
if (is_match_route) if (is_match_route)
{ {
std::optional<std::shared_ptr<IRouteExecutor>> maybe_executor_ptr = routes_pathes_ std::optional<std::shared_ptr<IRouteExecutor>> maybe_executor_ptr = routes_pathes_
.at(route) .at(req.target())
->FindExecutor(req.method()); ->FindExecutor(req.method());
if (maybe_executor_ptr.has_value()) if (maybe_executor_ptr.has_value())
@@ -192,7 +191,7 @@ public:
} }
} }
urls::url_view parsed_view = urls::parse_uri_reference(route).value(); urls::url_view parsed_view = urls::parse_uri_reference(req.target()).value();
auto segs = parsed_view.segments(); auto segs = parsed_view.segments();
std::vector<std::string> parts; std::vector<std::string> parts;