From fbf703b35cbc5b7856ed76fcf4fa75a483d01eda Mon Sep 17 00:00:00 2001 From: Joseph Aquino Date: Thu, 25 Dec 2025 19:25:05 -0500 Subject: [PATCH] changes to strings --- src/shellUtils.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/shellUtils.cpp b/src/shellUtils.cpp index 59b9203..2afb507 100644 --- a/src/shellUtils.cpp +++ b/src/shellUtils.cpp @@ -10,7 +10,8 @@ namespace sh { Command getCommand(std::string_view input) { - if (commandMap.contains(input.substr(0, input.find(' ')))) + if (commandMap.contains(input. + substr(0, input.find(' ')))) { return commandMap.at(input.substr(0, input.find(' '))); } @@ -23,7 +24,7 @@ namespace sh std::optional isExec(const std::string& input) { - const std::string pathEnv {std::getenv("PATH")}; + const std::string_view pathEnv {std::getenv("PATH")}; #if _WIN32 constexpr char delimiter {';'}; #else @@ -34,7 +35,9 @@ namespace sh while (nextDelimIndex != std::string::npos) { std::string currentPath {pathEnv.substr(startCharIndex, nextDelimIndex - startCharIndex)}; - std::string fullPath {currentPath + "/" + input}; + std::string fullPath; + fullPath.append(currentPath).append("/").append(input); + namespace fs = std::filesystem; if (!fs::exists(fullPath)) @@ -58,7 +61,7 @@ namespace sh void printType(const std::string& input) { - const std::string command {input.substr(0, input.find(' '))}; + const std::string_view command {input.substr(0, input.find(' '))}; if (commandMap.contains(command)) { std::cout << command; @@ -66,9 +69,10 @@ namespace sh return; } - if (auto fullPath {isExec(input)}) + if (const auto fullPath {isExec(input)}) { - std::cout << command << " is " << fullPath.value() << "\n"; + std::cout << command; + std::cout << " is " << fullPath.value() << "\n"; return; }