mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-24 07:58:34 +01:00
fix so multiple strings can be cached per id to support <plurals>
strings crossing jni boundary.
This commit is contained in:
parent
328300c8a2
commit
36839ac82b
1 changed files with 48 additions and 14 deletions
|
@ -28,6 +28,8 @@
|
||||||
#include "paths.h"
|
#include "paths.h"
|
||||||
#include "LocalizedStrIncludes.h"
|
#include "LocalizedStrIncludes.h"
|
||||||
|
|
||||||
|
#define MAX_QUANTITY_STRS 4
|
||||||
|
|
||||||
typedef struct _TimerStorage {
|
typedef struct _TimerStorage {
|
||||||
XWTimerProc proc;
|
XWTimerProc proc;
|
||||||
void* closure;
|
void* closure;
|
||||||
|
@ -39,6 +41,7 @@ typedef struct _AndUtil {
|
||||||
jobject jutil; /* global ref to object implementing XW_UtilCtxt */
|
jobject jutil; /* global ref to object implementing XW_UtilCtxt */
|
||||||
TimerStorage timerStorage[NUM_TIMERS_PLUS_ONE];
|
TimerStorage timerStorage[NUM_TIMERS_PLUS_ONE];
|
||||||
XP_UCHAR* userStrings[N_AND_USER_STRINGS];
|
XP_UCHAR* userStrings[N_AND_USER_STRINGS];
|
||||||
|
XP_U32 userStringsBits;
|
||||||
#ifdef XWFEATURE_DEVID
|
#ifdef XWFEATURE_DEVID
|
||||||
XP_UCHAR* devIDStorage;
|
XP_UCHAR* devIDStorage;
|
||||||
#endif
|
#endif
|
||||||
|
@ -436,22 +439,42 @@ and_util_getUserQuantityString( XW_UtilCtxt* uc, XP_U16 stringCode, XP_U16 quant
|
||||||
UTIL_CBK_HEADER("getUserQuantityString", "(II)Ljava/lang/String;" );
|
UTIL_CBK_HEADER("getUserQuantityString", "(II)Ljava/lang/String;" );
|
||||||
int index = stringCode - 1; /* see LocalizedStrIncludes.h */
|
int index = stringCode - 1; /* see LocalizedStrIncludes.h */
|
||||||
XP_ASSERT( index < VSIZE( util->userStrings ) );
|
XP_ASSERT( index < VSIZE( util->userStrings ) );
|
||||||
|
XP_UCHAR** ptrs;
|
||||||
|
|
||||||
if ( ! util->userStrings[index] ) {
|
util->userStringsBits |= 1 << index;
|
||||||
jstring jresult = (*env)->CallObjectMethod( env, util->jutil, mid,
|
ptrs = (XP_UCHAR**)util->userStrings[index];
|
||||||
stringCode, quantity );
|
if ( !ptrs ) {
|
||||||
jsize len = (*env)->GetStringUTFLength( env, jresult );
|
ptrs = (XP_UCHAR**)XP_CALLOC( util->util.mpool, MAX_QUANTITY_STRS * sizeof(*ptrs) );
|
||||||
XP_UCHAR* buf = XP_MALLOC( util->util.mpool, len + 1 );
|
util->userStrings[index] = (XP_UCHAR*)ptrs;
|
||||||
|
|
||||||
const char* jchars = (*env)->GetStringUTFChars( env, jresult, NULL );
|
|
||||||
XP_MEMCPY( buf, jchars, len );
|
|
||||||
buf[len] = '\0';
|
|
||||||
(*env)->ReleaseStringUTFChars( env, jresult, jchars );
|
|
||||||
deleteLocalRef( env, jresult );
|
|
||||||
util->userStrings[index] = buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result = util->userStrings[index];
|
jstring jresult = (*env)->CallObjectMethod( env, util->jutil, mid,
|
||||||
|
stringCode, quantity );
|
||||||
|
const char* jchars = (*env)->GetStringUTFChars( env, jresult, NULL );
|
||||||
|
int indx = 0;
|
||||||
|
for ( ; indx < MAX_QUANTITY_STRS; ++indx ) {
|
||||||
|
if ( !ptrs[indx] ) {
|
||||||
|
XP_LOGF( "%s: found empty slot %d for %s", __func__, indx, jchars );
|
||||||
|
break;
|
||||||
|
} else if ( 0 == XP_STRCMP( jchars, ptrs[indx] ) ) {
|
||||||
|
XP_LOGF( "%s: found %s at slot %d", __func__, jchars, indx );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !ptrs[indx] ) {
|
||||||
|
XP_ASSERT( indx < MAX_QUANTITY_STRS );
|
||||||
|
jsize len = (*env)->GetStringUTFLength( env, jresult );
|
||||||
|
XP_UCHAR* buf = XP_MALLOC( util->util.mpool, len + 1 );
|
||||||
|
XP_MEMCPY( buf, jchars, len );
|
||||||
|
buf[len] = '\0';
|
||||||
|
ptrs[indx] = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
(*env)->ReleaseStringUTFChars( env, jresult, jchars );
|
||||||
|
deleteLocalRef( env, jresult );
|
||||||
|
|
||||||
|
result = ptrs[indx];
|
||||||
UTIL_CBK_TAIL();
|
UTIL_CBK_TAIL();
|
||||||
LOG_RETURNF( "%s", result );
|
LOG_RETURNF( "%s", result );
|
||||||
return result;
|
return result;
|
||||||
|
@ -780,7 +803,18 @@ destroyUtil( XW_UtilCtxt** utilc )
|
||||||
for ( int ii = 0; ii < VSIZE(util->userStrings); ++ii ) {
|
for ( int ii = 0; ii < VSIZE(util->userStrings); ++ii ) {
|
||||||
XP_UCHAR* ptr = util->userStrings[ii];
|
XP_UCHAR* ptr = util->userStrings[ii];
|
||||||
if ( NULL != ptr ) {
|
if ( NULL != ptr ) {
|
||||||
XP_FREE( util->util.mpool, ptr );
|
if ( 0 == (util->userStringsBits & (1 << ii)) ) {
|
||||||
|
XP_FREE( util->util.mpool, ptr );
|
||||||
|
} else {
|
||||||
|
XP_UCHAR** ptrs = (XP_UCHAR**)ptr;
|
||||||
|
for ( int jj = 0; jj < MAX_QUANTITY_STRS; ++jj ) {
|
||||||
|
ptr = ptrs[jj];
|
||||||
|
if ( !!ptr ) {
|
||||||
|
XP_FREE( util->util.mpool, ptr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
XP_FREE( util->util.mpool, ptrs );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue