PageRenderTime 95ms CodeModel.GetById 18ms RepoModel.GetById 4ms app.codeStats 0ms

/tags/rel-1-3-29/SWIG/Examples/test-suite/li_cwstring.i

#
Swig | 98 lines | 82 code | 16 blank | 0 comment | 0 complexity | bc97dbca127356527f216ac12c24cabf MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module li_cwstring
  2. %include "cwstring.i"
  3. #ifndef SWIG_CWSTRING_UNIMPL
  4. %cwstring_input_binary(wchar_t *in, int n);
  5. %cwstring_bounded_output(wchar_t *out1, 512);
  6. %cwstring_chunk_output(wchar_t *out2, 64);
  7. %cwstring_bounded_mutable(wchar_t *out3, 512);
  8. %cwstring_mutable(wchar_t *out4, 32);
  9. %cwstring_output_maxsize(wchar_t *out5, int max);
  10. %cwstring_output_withsize(wchar_t *out6, int *size);
  11. #ifdef __cplusplus
  12. %cwstring_output_allocate(wchar_t **out7, delete [] *$1);
  13. %cwstring_output_allocate_size(wchar_t **out8, int *size, delete [] *$1);
  14. #else
  15. %cwstring_output_allocate(wchar_t **out7, free(*$1));
  16. %cwstring_output_allocate_size(wchar_t **out8, int *size, free(*$1));
  17. #endif
  18. %inline %{
  19. int count(wchar_t *in, int n, wchar_t c) {
  20. int r = 0;
  21. while (n > 0) {
  22. if (*in == c) {
  23. r++;
  24. }
  25. in++;
  26. --n;
  27. }
  28. return r;
  29. }
  30. void test1(wchar_t *out1) {
  31. wcscpy(out1,L"Hello World");
  32. }
  33. void test2(wchar_t *out2) {
  34. int i;
  35. for (i = 0; i < 64; i++) {
  36. *out2 = (wchar_t) i + 32;
  37. out2++;
  38. }
  39. }
  40. void test3(wchar_t *out3) {
  41. wcscat(out3,L"-suffix");
  42. }
  43. void test4(wchar_t *out4) {
  44. wcscat(out4,L"-suffix");
  45. }
  46. void test5(wchar_t *out5, int max) {
  47. int i;
  48. for (i = 0; i < max; i++) {
  49. out5[i] = 'x';
  50. }
  51. out5[max]='\0';
  52. }
  53. void test6(wchar_t *out6, int *size) {
  54. int i;
  55. for (i = 0; i < (*size/2); i++) {
  56. out6[i] = 'x';
  57. }
  58. *size = (*size/2);
  59. }
  60. void test7(wchar_t **out7) {
  61. #ifdef __cplusplus
  62. *out7 = new wchar_t[64];
  63. #else
  64. *out7 = malloc(64*sizeof(wchar_t));
  65. #endif
  66. (*out7)[0] = 0;
  67. wcscat(*out7,L"Hello world!");
  68. }
  69. void test8(wchar_t **out8, int *size) {
  70. int i;
  71. #ifdef __cplusplus
  72. *out8 = new wchar_t[64];
  73. #else
  74. *out8 = malloc(64*sizeof(wchar_t));
  75. #endif
  76. for (i = 0; i < 64; i++) {
  77. (*out8)[i] = (wchar_t) i + 32;
  78. }
  79. *size = 64;
  80. }
  81. %}
  82. #endif