mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
fix bug in dict_tilesToString that occurred only when a language had
two tiles starting with the same letter: use recursive search to try both paths in such cases.
This commit is contained in:
parent
79be03ac66
commit
fddd2c4ed5
1 changed files with 26 additions and 16 deletions
|
@ -157,35 +157,45 @@ dict_tilesToString( const DictionaryCtxt* dict, const Tile* tiles,
|
||||||
* run out of room in which to return tiles. Failure to match means return of
|
* run out of room in which to return tiles. Failure to match means return of
|
||||||
* XP_FALSE, but if we run out of room before failing we return XP_TRUE.
|
* XP_FALSE, but if we run out of room before failing we return XP_TRUE.
|
||||||
*/
|
*/
|
||||||
XP_Bool
|
static XP_S16
|
||||||
dict_tilesForString( const DictionaryCtxt* dict, const XP_UCHAR* str,
|
tilesForStringImpl( const DictionaryCtxt* dict, const XP_UCHAR* str,
|
||||||
Tile* tiles, XP_U16* nTilesP )
|
Tile* tiles, XP_U16 nTiles, XP_U16 nFound )
|
||||||
{
|
{
|
||||||
|
XP_S16 result = -1;
|
||||||
|
if ( nFound == nTiles || '\0' == str[0] ) {
|
||||||
|
result = nFound;
|
||||||
|
} else {
|
||||||
XP_U16 nFaces = dict_numTileFaces( dict );
|
XP_U16 nFaces = dict_numTileFaces( dict );
|
||||||
XP_U16 nTiles = 0;
|
|
||||||
XP_Bool success = XP_TRUE;
|
|
||||||
XP_ASSERT( 0 < *nTilesP );
|
|
||||||
|
|
||||||
while ( str[0] != '\0' && success && nTiles < *nTilesP ) {
|
|
||||||
Tile tile;
|
Tile tile;
|
||||||
const XP_UCHAR* prevstr = str;
|
|
||||||
for ( tile = 0; tile < nFaces; ++tile ) {
|
for ( tile = 0; tile < nFaces; ++tile ) {
|
||||||
if ( tile != dict->blankTile ) {
|
if ( tile != dict->blankTile ) {
|
||||||
const XP_UCHAR* facep = dict_getTileString( dict, tile );
|
const XP_UCHAR* facep = dict_getTileString( dict, tile );
|
||||||
XP_U16 faceLen = XP_STRLEN( facep );
|
XP_U16 faceLen = XP_STRLEN( facep );
|
||||||
if ( 0 == XP_STRNCMP( facep, str, faceLen ) ) {
|
if ( 0 == XP_STRNCMP( facep, str, faceLen ) ) {
|
||||||
tiles[nTiles++] = tile;
|
XP_S16 maxFound = tilesForStringImpl( dict, str + faceLen,
|
||||||
str += faceLen;
|
tiles, nTiles,
|
||||||
if ( nTiles == *nTilesP ) {
|
nFound + 1 );
|
||||||
|
if ( 0 <= maxFound ) {
|
||||||
|
tiles[nFound] = tile;
|
||||||
|
result = maxFound;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
success = str > prevstr;
|
|
||||||
}
|
}
|
||||||
XP_ASSERT( nTiles <= *nTilesP );
|
return result;
|
||||||
*nTilesP = nTiles;
|
} /* tilesForStringImpl */
|
||||||
|
|
||||||
|
XP_Bool
|
||||||
|
dict_tilesForString( const DictionaryCtxt* dict, const XP_UCHAR* str,
|
||||||
|
Tile* tiles, XP_U16* nTilesP )
|
||||||
|
{
|
||||||
|
XP_S16 nFound = tilesForStringImpl( dict, str, tiles, *nTilesP, 0 );
|
||||||
|
XP_Bool success = 0 <= nFound;
|
||||||
|
if ( success ) {
|
||||||
|
*nTilesP = nFound;
|
||||||
|
}
|
||||||
return success;
|
return success;
|
||||||
} /* dict_tilesForString */
|
} /* dict_tilesForString */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue