Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Convert selectStr to uint32_t

  • Loading branch information...
commit 18863fff797419c41547d5c63711b9183a203b83 1 parent 344411c
@kanru kanru authored
View
2  include/internal/chewing-private.h
@@ -196,7 +196,7 @@ typedef struct {
uint16_t phoneSeq[ MAX_PHONE_SEQ_LEN ];
int nPhoneSeq;
- char selectStr[ MAX_PHONE_SEQ_LEN ][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ];
+ uint32_t selectStr[ MAX_PHONE_SEQ_LEN ][ MAX_PHONE_SEQ_LEN + 1 ];
IntervalType selectInterval[ MAX_PHONE_SEQ_LEN ];
int nSelect;
IntervalType preferInterval[ MAX_INTERVAL ]; /* add connect points */
View
8 include/internal/tree-private.h
@@ -11,6 +11,8 @@
#ifndef _CHEWING_TREE_PRIVATE_H
#define _CHEWING_TREE_PRIVATE_H
+#include <inttypes.h>
+
#define IS_USER_PHRASE 1
#define IS_DICT_PHRASE 0
@@ -18,9 +20,9 @@ int InitTree( ChewingData *pgdata, const char *prefix );
void TerminateTree( ChewingData *pgdata );
int Phrasing( ChewingData *pgdata, PhrasingOutput *ppo, uint16_t phoneSeq[], int nPhoneSeq,
- char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
- IntervalType selectInterval[], int nSelect,
- int bArrBrkpt[], int bUserArrCnnct[] );
+ uint32_t selectStr[][MAX_PHONE_SEQ_LEN + 1],
+ IntervalType selectInterval[], int nSelect,
+ int bArrBrkpt[], int bUserArrCnnct[] );
int IsIntersect( IntervalType in1, IntervalType in2 );
int TreeFindPhrase( ChewingData *pgdata, int begin, int end, const uint16_t *phoneSeq );
View
16 src/chewingutil.c
@@ -672,7 +672,7 @@ int AddChi( uint16_t phone, ChewingData *pgdata )
memmove(
&( pgdata->phoneSeq[ cursor + 1 ] ),
&( pgdata->phoneSeq[ cursor ] ) ,
- sizeof( uint16_t ) * ( pgdata->nPhoneSeq - cursor ) );
+ sizeof(uint16_t) * ( pgdata->nPhoneSeq - cursor ) );
pgdata->phoneSeq[ cursor ] = phone;
pgdata->nPhoneSeq ++;
@@ -680,7 +680,7 @@ int AddChi( uint16_t phone, ChewingData *pgdata )
memmove(
&( pgdata->chiSymbolBuf[ pgdata->chiSymbolCursor + 1 ] ),
&( pgdata->chiSymbolBuf[ pgdata->chiSymbolCursor ] ) ,
- sizeof( uint32_t ) * ( pgdata->chiSymbolBufLen - pgdata->chiSymbolCursor ) );
+ sizeof(uint32_t) * ( pgdata->chiSymbolBufLen - pgdata->chiSymbolCursor ) );
/* "0" means Chinese word */
pgdata->chiSymbolBuf[ pgdata->chiSymbolCursor ] = 0;
pgdata->chiSymbolBufLen++;
@@ -707,11 +707,13 @@ static void ShowChewingData( ChewingData *pgdata )
PhoneSeqCursor( pgdata ),
pgdata->nSelect );
for ( i = 0; i < pgdata->nSelect; i++ ) {
+#if FIXME
DEBUG_OUT(
" %14s%4d%4d\n",
pgdata->selectStr[ i ],
pgdata->selectInterval[ i ].from,
pgdata->selectInterval[ i ].to );
+#endif
}
DEBUG_OUT( "bUserArrCnnct : " );
@@ -964,9 +966,9 @@ int AddSelect( ChewingData *pgdata, int sel_i )
nSelect = pgdata->nSelect;
/* change "selectStr" , "selectInterval" , and "nSelect" of ChewingData */
- u32tou8cpy( pgdata->selectStr[ nSelect ],
- pgdata->choiceInfo.totalChoiceStr[ sel_i ],
- 0, length );
+ memcpy( pgdata->selectStr[ nSelect ],
+ pgdata->choiceInfo.totalChoiceStr[ sel_i ],
+ sizeof(uint32_t) * length );
cursor = PhoneSeqCursor( pgdata );
pgdata->selectInterval[ nSelect ].from = cursor;
pgdata->selectInterval[ nSelect ].to = cursor + length;
@@ -1016,7 +1018,9 @@ void RemoveSelectElement( int i, ChewingData *pgdata )
if ( --pgdata->nSelect == i )
return;
pgdata->selectInterval[ i ] = pgdata->selectInterval[ pgdata->nSelect ];
- strcpy( pgdata->selectStr[ i ], pgdata->selectStr[ pgdata->nSelect ] );
+ memmove( pgdata->selectStr[ i ],
+ pgdata->selectStr[ pgdata->nSelect ],
+ sizeof(pgdata->selectStr[0]) );
}
static int ChewingKillSelectIntervalAcross( int cursor, ChewingData *pgdata )
View
6 src/choice.c
@@ -62,9 +62,9 @@ static void ChangeSelectIntervalAndBreakpoint(
if ( ( user_alloc = ( to - from ) ) == 0 )
return;
- ueStrNCpy( pgdata->selectStr[ pgdata->nSelect ],
- str,
- user_alloc, 1);
+ u8tou32cpy( pgdata->selectStr[ pgdata->nSelect ],
+ str, user_alloc );
+ pgdata->selectStr[ pgdata->nSelect ][ user_alloc ] = 0;
pgdata->nSelect++;
if ( user_alloc > 1 ) {
View
47 src/tree.c
@@ -168,8 +168,8 @@ static int CheckBreakpoint( int from, int to, int bArrBrkpt[] )
static int CheckUserChoose(
ChewingData *pgdata,
uint16_t *new_phoneSeq, int from , int to,
- Phrase **pp_phr,
- char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
+ Phrase **pp_phr,
+ uint32_t selectStr[][MAX_PHONE_SEQ_LEN + 1],
IntervalType selectInterval[], int nSelect )
{
IntervalType inte, c;
@@ -211,10 +211,13 @@ static int CheckUserChoose(
* 'selectStr[chno]' test if not ok then return 0,
* if ok then continue to test. */
len = c.to - c.from;
- if ( memcmp(
- ueStrSeek( pUserPhraseData->wordSeq, c.from - from ),
- selectStr[ chno ],
- ueStrNBytes( selectStr[ chno ], len ) ) )
+ uint32_t buf[ MAX_PHONE_SEQ_LEN + 1 ];
+ u8tou32cpy( buf,
+ ueStrSeek( pUserPhraseData->wordSeq,
+ c.from - from ),
+ len );
+ if ( memcmp( buf, selectStr[ chno ],
+ sizeof(uint32_t) * len ) )
break;
}
@@ -245,8 +248,8 @@ static int CheckUserChoose(
* their intersections are the same */
static int CheckChoose(
ChewingData *pgdata,
- int ph_id, int from, int to, Phrase **pp_phr,
- char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
+ int ph_id, int from, int to, Phrase **pp_phr,
+ uint32_t selectStr[][MAX_PHONE_SEQ_LEN + 1],
IntervalType selectInterval[], int nSelect )
{
IntervalType inte, c;
@@ -270,10 +273,14 @@ static int CheckChoose(
* then continue to test
*/
len = c.to - c.from;
- if ( memcmp(
- ueStrSeek( phrase->phrase, c.from - from ),
- selectStr[ chno ],
- ueStrNBytes( selectStr[ chno ], len ) ) )
+
+ uint32_t buf[ MAX_PHONE_SEQ_LEN + 1 ];
+ u8tou32cpy( buf,
+ ueStrSeek( phrase->phrase,
+ c.from - from ),
+ len );
+ if ( memcmp( buf, selectStr[ chno ],
+ sizeof(uint32_t) * len ) )
break;
}
else if ( IsIntersect( inte, selectInterval[ chno ] ) ) {
@@ -363,8 +370,8 @@ static void internal_release_Phrase( UsedPhraseMode mode, Phrase *pUser, Phrase
static void FindInterval(
ChewingData *pgdata,
uint16_t *phoneSeq, int nPhoneSeq,
- char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
- IntervalType selectInterval[], int nSelect,
+ uint32_t selectStr[][MAX_PHONE_SEQ_LEN + 1],
+ IntervalType selectInterval[], int nSelect,
int bArrBrkpt[], TreeDataType *ptd )
{
int end, begin, pho_id;
@@ -613,9 +620,9 @@ static void LoadChar( ChewingData *pgdata, uint32_t *buf, int buf_len, uint16_t
static void OutputRecordStr(
ChewingData *pgdata,
uint32_t *out_buf, int out_buf_len,
- int *record, int nRecord,
+ int *record, int nRecord,
uint16_t phoneSeq[], int nPhoneSeq,
- char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
+ uint32_t selectStr[][MAX_PHONE_SEQ_LEN + 1],
IntervalType selectInterval[],
int nSelect, TreeDataType *ptd )
{
@@ -632,9 +639,9 @@ static void OutputRecordStr(
for ( i = 0; i < nSelect; i++ ) {
inter.from = selectInterval[ i ].from;
inter.to = selectInterval[ i ].to ;
- u8tou32cpy( out_buf + inter.from,
- selectStr[ i ],
- ( inter.to - inter.from ) );
+ memcpy( out_buf + inter.from,
+ selectStr[ i ],
+ sizeof(uint32_t) * ( inter.to - inter.from ) );
}
}
@@ -957,7 +964,7 @@ static RecordNode* NextCut( TreeDataType *tdt, PhrasingOutput *ppo )
int Phrasing(
ChewingData *pgdata, /* FIXME: Remove other parameters since they are all in pgdata. */
PhrasingOutput *ppo, uint16_t phoneSeq[], int nPhoneSeq,
- char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
+ uint32_t selectStr[][MAX_PHONE_SEQ_LEN + 1],
IntervalType selectInterval[], int nSelect,
int bArrBrkpt[], int bUserArrCnnct[] )
{
Please sign in to comment.
Something went wrong with that request. Please try again.