PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/ruby/rubystrings.swg

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