mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-30 08:34:16 +01:00
fix edge cases in prefix matching
This commit is contained in:
parent
145317426d
commit
4cb848582e
2 changed files with 17 additions and 6 deletions
|
@ -194,13 +194,18 @@ findStartsWithChars( DictIter* iter, const XP_UCHAR* chars, XP_U16 charsOffset,
|
||||||
array_edge* edge, XP_U16 nTilesUsed )
|
array_edge* edge, XP_U16 nTilesUsed )
|
||||||
{
|
{
|
||||||
XP_S16 result = -1;
|
XP_S16 result = -1;
|
||||||
if ( NULL == edge || ( '\0' == chars[charsOffset] ) ) {
|
XP_U16 charsLen = XP_STRLEN( &chars[charsOffset] );
|
||||||
|
if ( NULL == edge ) {
|
||||||
|
if ( 0 == charsLen ) {
|
||||||
|
iter->nEdges = nTilesUsed;
|
||||||
|
result = charsOffset;
|
||||||
|
}
|
||||||
|
} else if ( 0 == charsLen ) {
|
||||||
iter->nEdges = nTilesUsed;
|
iter->nEdges = nTilesUsed;
|
||||||
result = charsOffset;
|
result = charsOffset;
|
||||||
} else {
|
} else {
|
||||||
const DictionaryCtxt* dict = iter->dict;
|
const DictionaryCtxt* dict = iter->dict;
|
||||||
XP_U16 nodeSize = dict->nodeSize;
|
XP_U16 nodeSize = dict->nodeSize;
|
||||||
XP_U16 charsLen = XP_STRLEN( &chars[charsOffset] );
|
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
Tile tile = EDGETILE( dict, edge );
|
Tile tile = EDGETILE( dict, edge );
|
||||||
const XP_UCHAR* facep = dict_getTileString( dict, tile );
|
const XP_UCHAR* facep = dict_getTileString( dict, tile );
|
||||||
|
@ -650,8 +655,14 @@ dict_findStartsWith( DictIter* iter, const XP_UCHAR* prefix )
|
||||||
ASSERT_INITED( iter );
|
ASSERT_INITED( iter );
|
||||||
array_edge* edge = dict_getTopEdge( iter->dict );
|
array_edge* edge = dict_getTopEdge( iter->dict );
|
||||||
XP_S16 offset = findStartsWithChars( iter, prefix, 0, edge, 0 );
|
XP_S16 offset = findStartsWithChars( iter, prefix, 0, edge, 0 );
|
||||||
if ( 0 < offset ) {
|
if ( 0 > offset ) {
|
||||||
if ( nextWord( iter ) ) {
|
/* not found; do nothing */
|
||||||
|
} else if ( 0 == offset ) {
|
||||||
|
if ( !firstWord( iter ) ) {
|
||||||
|
offset = -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( ACCEPT_ITER( iter, iter->nEdges ) || nextWord( iter ) ) {
|
||||||
DictPosition result = figurePosition( iter );
|
DictPosition result = figurePosition( iter );
|
||||||
iter->position = result;
|
iter->position = result;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1306,7 +1306,7 @@ walk_dict_test( const LaunchParams* XP_UNUSED_DBG(params),
|
||||||
for ( ii = 0; ii < count; ++ii ) {
|
for ( ii = 0; ii < count; ++ii ) {
|
||||||
gchar* prefix = (gchar*)g_slist_nth_data( testPrefixes, ii );
|
gchar* prefix = (gchar*)g_slist_nth_data( testPrefixes, ii );
|
||||||
XP_S16 lenMatched = dict_findStartsWith( &iter, prefix );
|
XP_S16 lenMatched = dict_findStartsWith( &iter, prefix );
|
||||||
if ( 0 < lenMatched ) {
|
if ( 0 <= lenMatched ) {
|
||||||
XP_UCHAR buf[32];
|
XP_UCHAR buf[32];
|
||||||
XP_UCHAR bufPrev[32] = {0};
|
XP_UCHAR bufPrev[32] = {0};
|
||||||
dict_wordToString( &iter, buf, VSIZE(buf) );
|
dict_wordToString( &iter, buf, VSIZE(buf) );
|
||||||
|
@ -1314,7 +1314,7 @@ walk_dict_test( const LaunchParams* XP_UNUSED_DBG(params),
|
||||||
XP_ASSERT( 0 == strncmp( buf, prefix, lenMatched ) );
|
XP_ASSERT( 0 == strncmp( buf, prefix, lenMatched ) );
|
||||||
|
|
||||||
DictPosition pos = dict_getPosition( &iter );
|
DictPosition pos = dict_getPosition( &iter );
|
||||||
XP_ASSERT( 0 == strncmp( buf, words[pos], lenMatched ) );
|
XP_ASSERT( 0 == strcmp( buf, words[pos] ) );
|
||||||
if ( pos > 0 ) {
|
if ( pos > 0 ) {
|
||||||
if ( !dict_getNthWord( &iter, pos-1, depth, &data ) ) {
|
if ( !dict_getNthWord( &iter, pos-1, depth, &data ) ) {
|
||||||
XP_ASSERT( 0 );
|
XP_ASSERT( 0 );
|
||||||
|
|
Loading…
Add table
Reference in a new issue