mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
new jni method to get lang code. Takes a dict's raw bytes and builds
a dict object just to fetch the code, which is pretty inefficient, so caching should be added later on the java side.
This commit is contained in:
parent
4208c33ecf
commit
cf6d8efb29
3 changed files with 31 additions and 6 deletions
|
@ -301,6 +301,7 @@ parseDict( AndDictionaryCtxt* ctxt, XP_U8* ptr, XP_U32 dictLength )
|
|||
ctxt->super.countsAndValues =
|
||||
(XP_U8*)XP_MALLOC(ctxt->super.mpool, nFaces*2);
|
||||
|
||||
ctxt->super.langCode = ptr[0] & 0x7F;
|
||||
ptr += 2; /* skip xloc header */
|
||||
for ( i = 0; i < nFaces*2; i += 2 ) {
|
||||
ctxt->super.countsAndValues[i] = *ptr++;
|
||||
|
@ -377,7 +378,9 @@ and_dictionary_destroy( DictionaryCtxt* dict )
|
|||
XP_FREE( ctxt->super.mpool, ctxt->super.faces );
|
||||
XP_FREE( ctxt->super.mpool, ctxt->super.facePtrs );
|
||||
XP_FREE( ctxt->super.mpool, ctxt->super.countsAndValues );
|
||||
XP_FREE( ctxt->super.mpool, ctxt->super.name );
|
||||
if ( NULL != ctxt->super.name ) {
|
||||
XP_FREE( ctxt->super.mpool, ctxt->super.name );
|
||||
}
|
||||
|
||||
XP_FREE( ctxt->super.mpool, ctxt->bytes );
|
||||
XP_FREE( ctxt->super.mpool, ctxt );
|
||||
|
@ -432,11 +435,13 @@ makeDict( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, jbyteArray jbytes,
|
|||
setBlankTile( &anddict->super );
|
||||
|
||||
/* copy the name */
|
||||
len = 1 + (*env)->GetStringUTFLength( env, jname );
|
||||
const char* chars = (*env)->GetStringUTFChars( env, jname, NULL );
|
||||
anddict->super.name = XP_MALLOC( mpool, len );
|
||||
XP_MEMCPY( anddict->super.name, chars, len );
|
||||
(*env)->ReleaseStringUTFChars( env, jname, chars );
|
||||
if ( NULL != jname ) {
|
||||
len = 1 + (*env)->GetStringUTFLength( env, jname );
|
||||
const char* chars = (*env)->GetStringUTFChars( env, jname, NULL );
|
||||
anddict->super.name = XP_MALLOC( mpool, len );
|
||||
XP_MEMCPY( anddict->super.name, chars, len );
|
||||
(*env)->ReleaseStringUTFChars( env, jname, chars );
|
||||
}
|
||||
|
||||
return (DictionaryCtxt*)anddict;
|
||||
}
|
||||
|
|
|
@ -258,6 +258,25 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1getInitialAddr
|
|||
setJAddrRec( env, jaddr, &addr );
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getLanguageCode
|
||||
(JNIEnv* env, jclass C, jbyteArray jDictBytes, jobject jniu )
|
||||
{
|
||||
#ifdef MEM_DEBUG
|
||||
MemPoolCtx* mpool = mpool_make();
|
||||
#endif
|
||||
JNIUtilCtxt* jniutil = makeJNIUtil( MPPARM(mpool) &env, jniu );
|
||||
DictionaryCtxt* dict = makeDict( MPPARM(mpool) env, jniutil,
|
||||
jDictBytes, NULL );
|
||||
jint code = dict_getLangCode( dict );
|
||||
dict_destroy( dict );
|
||||
destroyJNIUtil( &jniutil );
|
||||
#ifdef MEM_DEBUG
|
||||
mpool_destroy( mpool );
|
||||
#endif
|
||||
return code;
|
||||
}
|
||||
|
||||
/* Dictionary methods: don't use gamePtr */
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_eehouse_android_xw4_jni_XwJNI_dict_1tilesAreSame
|
||||
|
|
|
@ -205,4 +205,5 @@ public class XwJNI {
|
|||
// Dicts
|
||||
public static native boolean dict_tilesAreSame( int dictPtr1, int dictPtr2 );
|
||||
public static native String[] dict_getChars( int dictPtr );
|
||||
public static native int dict_getLanguageCode( byte[] dict, JNIUtils jniu );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue