PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/python_pybuf.i

#
Swig | 64 lines | 58 code | 4 blank | 2 comment | 0 complexity | 0c4196fa682b5475f90fd7dc4ec7a96e MD5 | raw file
 1%module python_pybuf
 2%include<pybuffer.i>
 3%include<cstring.i>
 4/*functions for the test case*/
 5%pybuffer_mutable_binary(char *buf1, int len);
 6%pybuffer_mutable_string(char *buf2);
 7%pybuffer_binary(const char *buf3, int len);
 8%pybuffer_string(const char *buf4);
 9
10%inline %{
11  void func1(char *buf1, int len)
12  {
13    int i;
14    for (i=0; i<len; ++i)
15      buf1[i] = 'a';
16    return;
17  }
18  void func2(char *buf2)
19  {
20    strcpy(buf2, "Hello world!");
21  }
22  int func3(const char *buf3, int len)
23  {
24    int count = 0;
25    int i;
26    for(i=0; i<len; ++i)
27      if (isalnum(buf3[i]))
28        ++count;
29    return count;
30  }
31  int func4(const char *buf4)
32  {
33    return strlen(buf4);
34  }  
35%}
36
37/*functions for the benchmark*/
38%pybuffer_mutable_string(char *str1);
39%cstring_mutable(char *str2);
40
41%inline %{
42void title(char *str) {
43    int outword = 1;
44    while(*str) {
45        if (isalnum(*str)) {
46            if (outword) {
47                outword = 0;
48                *str = toupper(*str);
49            }            
50        }
51        else {
52            outword = 0;
53        }
54        str++;
55    }
56}
57
58void title1(char *str1) {
59    title(str1);
60}
61void title2(char *str2) {
62    title(str2);
63}
64%}