changes to strings

This commit is contained in:
Joseph Aquino 2025-12-25 19:25:05 -05:00
parent f817fc9d7f
commit fbf703b35c
1 changed files with 10 additions and 6 deletions

View File

@ -10,7 +10,8 @@ namespace sh
{ {
Command getCommand(std::string_view input) 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(' '))); return commandMap.at(input.substr(0, input.find(' ')));
} }
@ -23,7 +24,7 @@ namespace sh
std::optional<std::string> isExec(const std::string& input) std::optional<std::string> isExec(const std::string& input)
{ {
const std::string pathEnv {std::getenv("PATH")}; const std::string_view pathEnv {std::getenv("PATH")};
#if _WIN32 #if _WIN32
constexpr char delimiter {';'}; constexpr char delimiter {';'};
#else #else
@ -34,7 +35,9 @@ namespace sh
while (nextDelimIndex != std::string::npos) while (nextDelimIndex != std::string::npos)
{ {
std::string currentPath {pathEnv.substr(startCharIndex, nextDelimIndex - startCharIndex)}; 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; namespace fs = std::filesystem;
if (!fs::exists(fullPath)) if (!fs::exists(fullPath))
@ -58,7 +61,7 @@ namespace sh
void printType(const std::string& input) 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)) if (commandMap.contains(command))
{ {
std::cout << command; std::cout << command;
@ -66,9 +69,10 @@ namespace sh
return; 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; return;
} }