source-engine/devtools/swigwin-1.3.34/Lib/perl5/jstring.i

49 lines
1.0 KiB
OpenEdge ABL
Raw Normal View History

2020-04-22 16:56:21 +00:00
%include <typemaps/valtypes.swg>
%fragment(SWIG_AsVal_frag(jstring),"header") {
SWIGINTERN int
SWIG_AsVal_dec(jstring)(SV *obj, jstring *val)
{
if (SvPOK(obj)) {
if (val) {
STRLEN len = 0;
char *cstr = SvPV(obj, len);
*val = JvNewStringLatin1(cstr, len);
}
return SWIG_OK;
}
return SWIG_ERROR;
}
}
%fragment(SWIG_From_frag(jstring),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(jstring)(jstring val)
{
SV *obj = sv_newmortal();
if (!val) {
sv_setsv(obj, &PL_sv_undef);
} else {
jsize len = JvGetStringUTFLength(val);
if (!len) {
sv_setsv(obj, &PL_sv_undef);
} else {
char *tmp = %new_array(len, char);
JvGetStringUTFRegion(val, 0, len, tmp);
sv_setpvn(obj, tmp, len);
SvUTF8_on(obj);
%delete_array(tmp);
}
}
return obj;
}
}
%typemaps_asvalfrom(%checkcode(STRING),
%arg(SWIG_AsVal(jstring)),
%arg(SWIG_From(jstring)),
%arg(SWIG_AsVal_frag(jstring)),
%arg(SWIG_From_frag(jstring)),
java::lang::String *);