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

Fix error loading LUT files with Turkish locale #984

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Changes from 2 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
26 changes: 24 additions & 2 deletions src/utils/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,42 @@ namespace StringUtils

using StringVec = std::vector<std::string>;

// Return the lower case character without taking into account locale like
// std::tolower, to avoid the "Turkish I" problem in file parsing.
inline unsigned char Lower(unsigned char c)
{
if(c >= 'A' && c <= 'Z') {
return c + ('a' - 'A');
}
else {
return c;
}
}

// Return the upper case character, without taking into account locale.
inline unsigned char Upper(unsigned char c)
{
if(c >= 'a' && c <= 'z') {
return c - ('a' - 'A');
}
else {
return c;
}
}

// Return the lower case string.
inline std::string Lower(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c) { return std::tolower(c); });
[](unsigned char c) { return Lower(c); });
return str;
}

// Return the upper case string.
inline std::string Upper(std::string str)
{
std::transform(str.begin(), str.end(), str.begin(),
[](unsigned char c) { return std::toupper(c); });
[](unsigned char c) { return Upper(c); });
return str;
}

Expand Down