handle BIND & CAPIT in bracketedLinearize for Java

This commit is contained in:
Krasimir Angelov
2017-09-25 10:36:38 +02:00
parent 91728a3a98
commit 66c20b1996
4 changed files with 91 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
#include <jni.h>
#include <gu/utf8.h>
#include <gu/string.h>
#include <pgf/pgf.h>
#include <pgf/linearizer.h>
#include "jni_utils.h"
#ifndef __MINGW32__
#include <alloca.h>
@@ -59,6 +61,35 @@ gu2j_string_buf(JNIEnv *env, GuStringBuf* sbuf) {
return gu2j_string_len(env, gu_string_buf_data(sbuf), gu_string_buf_length(sbuf));
}
JPGF_INTERNAL jstring
gu2j_string_capit(JNIEnv *env, GuString s, PgfCapitState capit) {
const char* utf8 = s;
size_t len = strlen(s);
jchar* utf16 = alloca(len*sizeof(jchar));
jchar* dst = utf16;
while (s-utf8 < len) {
GuUCS ucs = gu_utf8_decode((const uint8_t**) &s);
if (capit == PGF_CAPIT_FIRST) {
ucs = gu_ucs_to_upper(ucs);
capit == PGF_CAPIT_NONE;
} else if (capit == PGF_CAPIT_NEXT) {
ucs = gu_ucs_to_upper(ucs);
}
if (ucs <= 0xFFFF) {
*dst++ = ucs;
} else {
ucs -= 0x10000;
*dst++ = 0xD800+((ucs >> 10) & 0x3FF);
*dst++ = 0xDC00+(ucs & 0x3FF);
}
}
return (*env)->NewString(env, utf16, dst-utf16);
}
JPGF_INTERNAL GuString
j2gu_string(JNIEnv *env, jstring s, GuPool* pool) {
GuString str = (*env)->GetStringUTFChars(env, s, 0);