1 %include <typemaps/valtypes.swg> 2 3 %fragment(SWIG_AsVal_frag(jstring),"header") { 4 SWIGINTERN int 5 SWIG_AsVal_dec(jstring)(SV *obj, jstring *val) 6 { 7 if (SvPOK(obj)) { 8 if (val) { 9 STRLEN len = 0; 10 char *cstr = SvPV(obj, len); 11 *val = JvNewStringLatin1(cstr, len); 12 } 13 return SWIG_OK; 14 } 15 return SWIG_ERROR; 16 } 17 } 18 19 %fragment(SWIG_From_frag(jstring),"header") { 20 SWIGINTERNINLINE SV * 21 SWIG_From_dec(jstring)(jstring val) 22 { 23 SV *obj = sv_newmortal(); 24 if (!val) { 25 sv_setsv(obj, &PL_sv_undef); 26 } else { 27 jsize len = JvGetStringUTFLength(val); 28 if (!len) { 29 sv_setsv(obj, &PL_sv_undef); 30 } else { 31 char *tmp = %new_array(len, char); 32 JvGetStringUTFRegion(val, 0, len, tmp); 33 sv_setpvn(obj, tmp, len); 34 SvUTF8_on(obj); 35 %delete_array(tmp); 36 } 37 } 38 return obj; 39 } 40 } 41 42 %typemaps_asvalfrom(%checkcode(STRING), 43 %arg(SWIG_AsVal(jstring)), 44 %arg(SWIG_From(jstring)), 45 %arg(SWIG_AsVal_frag(jstring)), 46 %arg(SWIG_From_frag(jstring)), 47 java::lang::String *); 48 49