Skip to content

Commit

Permalink
Do not check phrase longer than MAX_PHRASE_LEN
Browse files Browse the repository at this point in the history
Part of #73
  • Loading branch information
czchen committed Sep 15, 2013
1 parent 39dd216 commit 7b243b1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ static void FindInterval( ChewingData *pgdata, TreeDataType *ptd )
uint16_t new_phoneSeq[ MAX_PHONE_SEQ_LEN ];

for ( begin = 0; begin < pgdata->nPhoneSeq; begin++ ) {
for ( end = begin; end < pgdata->nPhoneSeq; end++ ) {
for ( end = begin; end < min( pgdata->nPhoneSeq, begin + MAX_PHRASE_LEN ); end++ ) {
if ( ! CheckBreakpoint( begin, end + 1, pgdata->bArrBrkpt ) )
continue;
break;

/* set new_phoneSeq */
memcpy(
Expand Down
24 changes: 24 additions & 0 deletions test/test-bopomofo.c
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,28 @@ void test_zuin_buffer()
chewing_delete( ctx );
}

void test_longest_phrase()
{
ChewingContext *ctx;
IntervalType it;

ctx = chewing_new();

type_keystroke_by_string( ctx, "rup ji up6ji 1j4bj6y4ru32k7e.3ji "
/* ㄐㄧㄣ ㄨㄛ ㄧㄣˊ ㄨㄛ ㄅㄨˋ ㄖㄨˊ ㄗˋ ㄐㄧˇ ㄉㄜ˙ ㄍㄡˇ ㄨㄛ */ );
ok_preedit_buffer( ctx, "\xE9\x87\x91\xE7\xAA\xA9\xE9\x8A\x80\xE7\xAA\xA9\xE4\xB8\x8D\xE5\xA6\x82\xE8\x87\xAA\xE5\xB7\xB1\xE7\x9A\x84\xE7\x8B\x97\xE7\xAA\xA9"
/* 金窩銀窩不如自己的狗窩 */ );

chewing_interval_Enumerate( ctx );

ok( chewing_interval_hasNext( ctx ) == 1, "shall have next interval" );
chewing_interval_Get( ctx, &it );
ok( it.from == 0 && it.to == 11, "interval (%d, %d) shall be (0, 11)",
it.from, it.to );

chewing_delete( ctx );
}

int main()
{
putenv( "CHEWING_PATH=" CHEWING_DATA_PREFIX );
Expand All @@ -680,5 +702,7 @@ int main()
test_get_phoneSeq();
test_zuin_buffer();

test_longest_phrase();

return exit_status();
}

0 comments on commit 7b243b1

Please sign in to comment.