Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ColorFromXOrgAppColorName both smaller and more correct #16824

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/types/colorTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void Utils::InitializeColorTable(const std::span<COLORREF> table)
std::optional<til::color> Utils::ColorFromXOrgAppColorName(const std::wstring_view wstr) noexcept
try
{
std::stringstream ss;
std::string stem;
size_t variantIndex = 0;
auto foundVariant = false;
for (const auto c : wstr)
Expand All @@ -485,7 +485,7 @@ try
}

// Ignore spaces.
if (std::iswspace(c))
if (c == L' ' || c == L'\f' || c == L'\n' || c == L'\r' || c == L'\t' || c == L'\v')
lhecker marked this conversation as resolved.
Show resolved Hide resolved
{
continue;
}
Expand All @@ -498,11 +498,10 @@ try
return std::nullopt;
}

ss << gsl::narrow_cast<char>(std::towlower(c));
stem += gsl::narrow_cast<char>(til::tolower_ascii(c));
}

auto name = ss.str();
const auto variantColorIter = xorgAppVariantColorTable.find(name);
const auto variantColorIter = xorgAppVariantColorTable.find(stem);
if (variantColorIter != xorgAppVariantColorTable.end())
{
const auto colors = variantColorIter->second;
Expand All @@ -513,7 +512,7 @@ try
}

// Calculate the color value for gray0 - gray99.
if ((name == "gray" || name == "grey") && foundVariant)
if ((stem == "gray" || stem == "grey") && foundVariant)
{
if (variantIndex > 100) // size_t is unsigned, so >=0 is implicit
{
Expand All @@ -523,7 +522,7 @@ try
return til::color{ component, component, component };
}

const auto colorIter = xorgAppColorTable.find(name);
const auto colorIter = xorgAppColorTable.find(stem);
if (colorIter != xorgAppColorTable.end())
{
return colorIter->second;
Expand Down
Loading