PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/ruby/rubywstrings.swg

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