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

Improve handling of different capitalizations of "Across" and "Down". #143

Merged
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions puz/Clue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,18 @@ class PUZ_API Clues : public std::map<string_t, ClueList>

ClueList & SetClueList(const string_t & direction, const ClueList & cluelist)
{
operator[](direction) = cluelist;
ClueList & ret = operator[](direction);
// Normalize different capitalizations of "Across" and "Down", since these have special meaning.
// We still retain the original direction in the title field.
string_t canonical_direction;
if (CaseInsensitiveEquals(direction, puzT("Across")))
canonical_direction = puzT("Across");
else if (CaseInsensitiveEquals(direction, puzT("Down")))
canonical_direction = puzT("Down");
else
canonical_direction = direction;

operator[](canonical_direction) = cluelist;
ClueList & ret = operator[](canonical_direction);
if (ret.GetTitle().empty())
ret.SetTitle(direction);
return ret;
Expand Down
15 changes: 15 additions & 0 deletions puz/puzstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,21 @@ bool EndsWith(const string_t & str, const string_t & cmp)
str.compare(str.size() - cmp.size(), cmp.size(), cmp) == 0;
}

bool CaseInsensitiveEquals(const string_t& a, const string_t& b)
{
unsigned int sz = a.size();
if (b.size() != sz)
return false;
for (unsigned int i = 0; i < sz; ++i)
#if PUZ_UNICODE
if (towlower(a[i]) != towlower(b[i]))
#else
if (tolower(a[i]) != tolower(b[i]))
#endif
return false;
return true;
}

//----------------------------------------------------------------------------
// Convert between formatted / unformatted
//----------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions puz/puzstring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ int ToInt(const string_t & str);
bool StartsWith(const string_t & str, const string_t & cmp);
bool EndsWith(const string_t & str, const string_t & cmp);

bool CaseInsensitiveEquals(const string_t& a, const string_t& b);

// XML stuff
enum {
UNESCAPE_BR = 1,
Expand Down