From bd98a34dcc35296beb4af7bdad3866516dfcc276 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Mon, 10 Nov 2025 00:22:36 +0100 Subject: [PATCH 1/4] Refactor: use string_view --- include/argparse.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index 30ac958..1b22129 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -1036,7 +1036,7 @@ namespace argparse } } - auto check_errors(std::string const & value, std::ranges::view auto tokens) const -> void + auto check_errors(std::string_view value, std::ranges::view auto tokens) const -> void { if (!m_base.has_nargs() && value.empty() && tokens.empty()) { @@ -1116,7 +1116,7 @@ namespace argparse m_value = m_base.get_const(); } - auto check_errors(std::string const & value, std::ranges::view auto /* tokens */) const -> void + auto check_errors(std::string_view value, std::ranges::view auto /* tokens */) const -> void { if (!value.empty()) { @@ -1148,7 +1148,7 @@ namespace argparse m_value = true; } - auto check_errors(std::string const & value, std::ranges::view auto /* tokens */) const -> void + auto check_errors(std::string_view value, std::ranges::view auto /* tokens */) const -> void { if (!value.empty()) { @@ -1180,7 +1180,7 @@ namespace argparse m_value = false; } - auto check_errors(std::string const & value, std::ranges::view auto /* tokens */) const -> void + auto check_errors(std::string_view value, std::ranges::view auto /* tokens */) const -> void { if (!value.empty()) { @@ -1212,7 +1212,7 @@ namespace argparse throw HelpRequested(); } - auto check_errors(std::string const & /* value */, std::ranges::view auto /* tokens */) const -> void + auto check_errors(std::string_view /* value */, std::ranges::view auto /* tokens */) const -> void { } @@ -1239,7 +1239,7 @@ namespace argparse throw VersionRequested(); } - auto check_errors(std::string const & /* value */, std::ranges::view auto /* tokens */) const -> void + auto check_errors(std::string_view /* value */, std::ranges::view auto /* tokens */) const -> void { } @@ -1273,7 +1273,7 @@ namespace argparse } } - auto check_errors(std::string const & value, std::ranges::view auto /* tokens */) const -> void + auto check_errors(std::string_view value, std::ranges::view auto /* tokens */) const -> void { if (!value.empty()) { @@ -1331,7 +1331,7 @@ namespace argparse } } - auto check_errors(std::string const & value, std::ranges::view auto tokens) const -> void + auto check_errors(std::string_view value, std::ranges::view auto tokens) const -> void { if (value.empty() && tokens.empty()) { @@ -1599,7 +1599,7 @@ namespace argparse return get_joined_names(); } - auto check_errors(std::string const & value, std::ranges::view auto tokens) const -> void + auto check_errors(std::string_view value, std::ranges::view auto tokens) const -> void { std::visit([&](auto const & action) { action.check_errors(value, tokens); }, m_action); } From dda9f4c9a1e80150f891374301e8504b0aa5120e Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Mon, 10 Nov 2025 00:35:51 +0100 Subject: [PATCH 2/4] Refactor: simplify code --- include/argparse.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index 1b22129..f5a5c8c 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -1537,9 +1537,8 @@ namespace argparse { if (auto const pos = arg.m_token.find('='); pos != std::string::npos) { - auto const value = arg.m_token.substr(pos + 1); it->m_consumed = true; - return value; + return arg.m_token.substr(pos + 1); } else { From 00a7b6f568984810509e62d8904c20866aaefa85 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Mon, 10 Nov 2025 00:36:08 +0100 Subject: [PATCH 3/4] Refactor: simplify code --- include/argparse.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index f5a5c8c..07984c0 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -1561,9 +1561,8 @@ namespace argparse } else { - auto const prefix = it->m_token.substr(0, pos); auto const value = it->m_token.substr(pos); - it->m_token = prefix; + it->m_token.resize(pos); return value; } } From b3e617d0d23458211209b3a067fcdb76b0d5d773 Mon Sep 17 00:00:00 2001 From: Krzysiek Karbowiak Date: Mon, 10 Nov 2025 00:41:38 +0100 Subject: [PATCH 4/4] Refactor: simplify code --- include/argparse.hpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/argparse.hpp b/include/argparse.hpp index 07984c0..9787e6a 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -1533,36 +1533,36 @@ namespace argparse auto consume_name(auto it, std::string_view name) const -> std::string { - if (auto const & arg = *it; arg.m_token.starts_with("--")) + if (auto & arg = *it; arg.m_token.starts_with("--")) { if (auto const pos = arg.m_token.find('='); pos != std::string::npos) { - it->m_consumed = true; + arg.m_consumed = true; return arg.m_token.substr(pos + 1); } else { - it->m_consumed = true; + arg.m_consumed = true; return ""; } } else { - if (it->m_token.size() != 2) + if (arg.m_token.size() != 2) { - auto const pos = it->m_token.find(name[1]); - it->m_token.erase(pos, 1); + auto const pos = arg.m_token.find(name[1]); + arg.m_token.erase(pos, 1); if (expects_argument()) { if (pos == 1) { - it->m_consumed = true; - return it->m_token.substr(pos); + arg.m_consumed = true; + return arg.m_token.substr(pos); } else { - auto const value = it->m_token.substr(pos); - it->m_token.resize(pos); + auto const value = arg.m_token.substr(pos); + arg.m_token.resize(pos); return value; } } @@ -1573,7 +1573,7 @@ namespace argparse } else { - it->m_consumed = true; + arg.m_consumed = true; return ""; } }