Skip to content

Commit

Permalink
Perform localized comparison via wstring
Browse files Browse the repository at this point in the history
On OS X and Windows the existing solution for localized comparison seems
to be struggling.  Try performing the comparison on std::wstring
rather than string, which should sidestep any character encoding issues.
  • Loading branch information
jbytheway committed May 1, 2020
1 parent 2b565c6 commit 8dc5697
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/translations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ std::string operator+( const translation &lhs, const translation &rhs )
}

bool localized_comparator::operator()( const std::string &l, const std::string &r ) const
{
return ( *this )( utf8_to_wstr( l ), utf8_to_wstr( r ) );
}

bool localized_comparator::operator()( const std::wstring &l, const std::wstring &r ) const
{
return std::locale()( l, r );
}
1 change: 1 addition & 0 deletions src/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ struct localized_comparator {
}

bool operator()( const std::string &, const std::string & ) const;
bool operator()( const std::wstring &, const std::wstring & ) const;
};

constexpr localized_comparator localized_compare{};
Expand Down

0 comments on commit 8dc5697

Please sign in to comment.