static size_t j2gu_string_offset(GuString s, size_t joffset) { const char* utf8 = s; while (joffset > 0) { gu_utf8_decode((const uint8_t**) &utf8); joffset--; } return utf8-s; }
static bool pgf_is_normal_ident(PgfCId id) { const uint8_t* p = (const uint8_t*) id; GuUCS ucs = gu_utf8_decode(&p); if (!pgf_is_ident_first(ucs)) return false; for (;;) { ucs = gu_utf8_decode(&p); if (ucs == 0) break; if (!pgf_is_ident_rest(ucs)) return false; } return true; }
static size_t gu2j_string_offset(GuString s, size_t offset) { const char* utf8 = s; size_t joffset = 0; while (utf8-s < offset) { gu_utf8_decode((const uint8_t**) &utf8); joffset++; } return joffset; }
static jstring gu2j_string(JNIEnv *env, GuString s) { 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 (ucs <= 0xFFFF) { *dst++ = ucs; } else { ucs -= 0x10000; *dst++ = 0xD800+((ucs >> 10) & 0x3FF); *dst++ = 0xDC00+(ucs & 0x3FF); } } return (*env)->NewString(env, utf16, dst-utf16); }