PageRenderTime 23ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/perl5/jstring.i

#
Swig | 48 lines | 44 code | 4 blank | 0 comment | 0 complexity | 496c46f5032b0677224af907c6590cdc MD5 | raw file
 1%include <typemaps/valtypes.swg>
 2
 3%fragment(SWIG_AsVal_frag(jstring),"header") {
 4SWIGINTERN int
 5SWIG_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") {
20SWIGINTERNINLINE SV *
21SWIG_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