Skip to content

Commit

Permalink
Merge pull request #208 from jpd236/coded-ipuz
Browse files Browse the repository at this point in the history
Add support for coded ipuz files.
  • Loading branch information
mrichards42 authored Sep 28, 2023
2 parents e66d5b5 + 61cf765 commit f2c5ebc
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions puz/formats/ipuz/load_ipuz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,29 @@ bool ipuzParser::DoLoadPuzzle(Puzzle * puz, json::Value * root)
{
json::Map * doc = root->AsMap();
try {
// Check kind
string_t kind = doc->PopArray(puzT("kind"))->at(0)->AsString();
if (kind.substr(kind.size() - 2) == puzT("#1"))
kind = kind.substr(0, kind.size() - 2);
if (kind == puzT("http://ipuz.org/crossword") ||
kind == puzT("http://ipuz.org/crossword/crypticcrossword")) {
// Regular crossword
} else if (kind == puzT("http://ipuz.org/crossword/diagramless")) {
// Diagramless crossword
puz->GetGrid().SetType(TYPE_DIAGRAMLESS);
} else {
// Check kind from most to least specific until we find a match
json::Array * kinds = doc->PopArray(puzT("kind"));
std::vector<json::Value*>::iterator i = kinds->end();
bool known_type = false;
while (i != kinds->begin() && !known_type) {
string_t kind = (*(--i))->AsString();
if (kind.substr(kind.size() - 2) == puzT("#1"))
kind = kind.substr(0, kind.size() - 2);
if (kind == puzT("http://ipuz.org/crossword") ||
kind == puzT("http://ipuz.org/crossword/crypticcrossword")) {
// Regular crossword
known_type = true;
} else if (kind == puzT("http://ipuz.org/crossword/diagramless")) {
// Diagramless crossword
known_type = true;
puz->GetGrid().SetType(TYPE_DIAGRAMLESS);
} else if (kind == puzT("http://crosswordnexus.com/ipuz/coded")) {
// Coded crossword
known_type = true;
puz->GetGrid().SetType(TYPE_CODED);
}
}
if (!known_type) {
throw LoadError("Unsupported ipuz kind");
}
}
Expand Down

0 comments on commit f2c5ebc

Please sign in to comment.