1/** 2 * @file rubywstrings.swg 3 * @author 4 * @date Fri May 4 17:49:40 2007 5 * 6 * @brief Currently, Ruby does not support Unicode or WChar properly, so these 7 * are still treated as char arrays for now. 8 * There are other libraries available that add support to this in 9 * ruby including WString, FXString, etc. 10 * 11 * 12 */ 13 14/* ------------------------------------------------------------ 15 * utility methods for wchar_t strings 16 * ------------------------------------------------------------ */ 17 18%fragment("SWIG_AsWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") { 19SWIGINTERN int 20SWIG_AsWCharPtrAndSize(VALUE obj, wchar_t **cptr, size_t *psize, int *alloc) 21{ 22 return SWIG_AsCharPtrAndSize( obj, (char**)cptr, psize, alloc); 23// VALUE tmp = 0; 24// bool ok = false; 25// if ( TYPE(obj) == T_STRING ) { 26// if (cptr) { 27// obj = tmp = SWIG_Unicode_FromObject(obj); 28// ok = true; 29// } 30// } 31// if (ok) { 32// Py_ssize_t len = PyUnicode_GetSize(obj); 33// rb_notimplement(); 34// if (cptr) { 35// *cptr = %new_array(len + 1, wchar_t); 36// SWIG_Unicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len); 37// (*cptr)[len] = 0; 38// } 39// if (psize) *psize = (size_t) len + 1; 40// if (alloc) *alloc = cptr ? SWIG_NEWOBJ : 0; 41// return SWIG_OK; 42// } else { 43// swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); 44// if (pwchar_descriptor) { 45// void * vptr = 0; 46// if (SWIG_ConvertPtr(obj, &vptr, pwchar_descriptor, 0) == SWIG_OK) { 47// if (cptr) *cptr = (wchar_t *)vptr; 48// if (psize) *psize = vptr ? (wcslen((wchar_t *)vptr) + 1) : 0; 49// return SWIG_OK; 50// } 51// } 52// } 53// return SWIG_TypeError; 54} 55} 56 57%fragment("SWIG_FromWCharPtrAndSize","header",fragment="<wchar.h>",fragment="SWIG_pwchar_descriptor") { 58SWIGINTERNINLINE VALUE 59SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size) 60{ 61 return SWIG_FromCharPtrAndSize( (const char*)carray, size); 62// if (carray) { 63// if (size > INT_MAX) { 64// swig_type_info* pwchar_descriptor = SWIG_pwchar_descriptor(); 65// return pwchar_descriptor ? 66// SWIG_NewPointerObj(%const_cast(carray,wchar_t *), pwchar_descriptor, 0) : Qnil; 67// } else { 68// return SWIG_Unicode_FromWideChar(carray, %numeric_cast(size,int)); 69// } 70// } else { 71// return Qnil; 72// } 73} 74} 75 76 77