Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/SshHostGenerator.cpp (C++)

Code before:

/*static*/ std::wstring SshHostGenerator::GetProfileName(const std::wstring_view& hostName) noexcept
{
    return std::wstring{ PROFILE_TITLE_PREFIX + hostName };
}

/*static*/ std::wstring SshHostGenerator::GetProfileIconPath() noexcept
{
    return PROFILE_ICON_PATH;
}

/*static*/ std::wstring SshHostGenerator::GetProfileCommandLine(const std::wstring_view& sshExePath, const std::wstring_view& hostName) noexcept
{
    return std::wstring(L"\"" + sshExePath + L"\" " + hostName);
}

/*static*/ bool SshHostGenerator::TryFindSshExePath(std::wstring& sshExePath) noexcept
{
    try
    {
        // OpenSSH is installed under System32 when installed via Optional Features
        if (std::filesystem::exists(wil::ExpandEnvironmentStringsW<std::wstring>(SSH_EXE_PATH1)))
        {
            sshExePath = SSH_EXE_PATH1;
            return true;
        }

        // OpenSSH (x86/x64) is installed under Program Files when installed via MSI
        if (std::filesystem::exists(wil::ExpandEnvironmentStringsW<std::wstring>(SSH_EXE_PATH2)))
        {
            sshExePath = SSH_EXE_PATH2;
            return true;
        }

        // OpenSSH (x86) is installed under Program Files x86 when installed via MSI on x64 machine
        if (std::filesystem::exists(wil::ExpandEnvironmentStringsW<std::wstring>(SSH_EXE_PATH3)))
        {
            sshExePath = SSH_EXE_PATH3;
            return true;
        }
    }
    CATCH_LOG();

    return false;
}

/*static*/ bool SshHostGenerator::TryParseConfigKeyValue(const std::wstring_view& line, std::wstring& key, std::wstring& value) noexcept
{
    try
    {
        if (!line.empty() && !line.starts_with(L"#"))

Review comment (suggestion):
You can use a for loop here. Something like...
```cpp
for (const auto& path : { SSH_EXE_PATH1, SSH_EXE_PATH2, SSH_EXE_PATH3 })
```

Code after:

using namespace ::Microsoft::Terminal::Settings::Model;
using namespace winrt::Microsoft::Terminal::Settings::Model;

/*static*/ const std::wregex SshHostGenerator::_configKeyValueRegex{ LR"(^\s*(\w+)\s+([^\s]+.*[^\s])\s*$)" };

/*static*/ std::wstring_view SshHostGenerator::_getProfileName(const std::wstring_view& hostName) noexcept
{
    return std::wstring_view{ L"" + PROFILE_TITLE_PREFIX + hostName };
}

/*static*/ std::wstring_view SshHostGenerator::_getProfileIconPath() noexcept
{
    return PROFILE_ICON_PATH;
}

/*static*/ std::wstring_view SshHostGenerator::_getProfileCommandLine(const std::wstring_view& sshExePath, const std::wstring_view& hostName) noexcept
{
    return std::wstring_view{ L"\"" + sshExePath + L"\" " + hostName };
}

/*static*/ bool SshHostGenerator::_tryFindSshExePath(std::wstring& sshExePath) noexcept
{
    try
    {
        for (const auto& path : { SSH_EXE_PATH1, SSH_EXE_PATH2, SSH_EXE_PATH3 })
        {
            if (std::filesystem::exists(wil::ExpandEnvironmentStringsW<std::wstring>(path.data())))
            {
                sshExePath = path;
                return true;
            }
        }
    }
    CATCH_LOG();

    return false;
}

/*static*/ bool SshHostGenerator::_tryParseConfigKeyValue(const std::wstring_view& line, std::wstring& key, std::wstring& value) noexcept
{
    try
    {
        if (!line.empty() && !line.starts_with(L"#"))
        {
            std::wstring input{ line };
            std::wsmatch match;
            if (std::regex_search(input, match, SshHostGenerator::_configKeyValueRegex))
            {
                key = match[1];
                value = match[2];