PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Lib/ruby/rubystrings.swg

#
Unknown | 61 lines | 58 code | 3 blank | 0 comment | 0 complexity | 114ebb212fa1ea9c237fb2c1652356ea MD5 | raw file
 1/* ------------------------------------------------------------
 2 *  utility methods for char strings 
 3 * ------------------------------------------------------------ */
 4
 5%fragment("SWIG_AsCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
 6SWIGINTERN int
 7SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
 8{
 9  if (TYPE(obj) == T_STRING) {
10    %#if defined(StringValuePtr)
11    char *cstr = StringValuePtr(obj); 
12    %#else
13    char *cstr = STR2CSTR(obj);
14    %#endif
15    size_t size = RSTRING_LEN(obj) + 1;
16    if (cptr)  {
17      if (alloc) {
18	if (*alloc == SWIG_NEWOBJ) {
19	  *cptr = %new_copy_array(cstr, size, char);
20	} else {
21	  *cptr = cstr;
22	  *alloc = SWIG_OLDOBJ;
23	}
24      }
25    }
26    if (psize) *psize = size;
27    return SWIG_OK;
28  } else {
29    swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
30    if (pchar_descriptor) {
31      void* vptr = 0;
32      if (SWIG_ConvertPtr(obj, &vptr, pchar_descriptor, 0) == SWIG_OK) {
33	if (cptr) *cptr = (char *)vptr;
34	if (psize) *psize = vptr ? (strlen((char*)vptr) + 1) : 0;
35	if (alloc) *alloc = SWIG_OLDOBJ;
36	return SWIG_OK;
37      }
38    }
39  }  
40  return SWIG_TypeError;
41}
42}
43
44%fragment("SWIG_FromCharPtrAndSize","header",fragment="SWIG_pchar_descriptor") {
45SWIGINTERNINLINE VALUE 
46SWIG_FromCharPtrAndSize(const char* carray, size_t size)
47{
48  if (carray) {
49    if (size > LONG_MAX) {
50      swig_type_info* pchar_descriptor = SWIG_pchar_descriptor();
51      return pchar_descriptor ? 
52	SWIG_NewPointerObj(%const_cast(carray,char *), pchar_descriptor, 0) : Qnil;
53    } else {
54      return rb_str_new(carray, %numeric_cast(size,long));
55    }
56  } else {
57    return Qnil;
58  }
59}
60}
61