forked from floooh/sokol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_util.py
57 lines (44 loc) · 1.35 KB
/
gen_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# common utility functions for all bindings generators
import re
re_1d_array = re.compile("^(?:const )?\w*\s*\*?\[\d*\]$")
re_2d_array = re.compile("^(?:const )?\w*\s*\*?\[\d*\]\[\d*\]$")
def is_1d_array_type(s):
return re_1d_array.match(s) is not None
def is_2d_array_type(s):
return re_2d_array.match(s) is not None
def is_array_type(s):
return is_1d_array_type(s) or is_2d_array_type(s)
def extract_array_type(s):
return s[:s.index('[')].strip()
def extract_array_sizes(s):
return s[s.index('['):].replace('[', ' ').replace(']', ' ').split()
def is_string_ptr(s):
return s == "const char *"
def is_const_void_ptr(s):
return s == "const void *"
def is_void_ptr(s):
return s == "void *"
def is_func_ptr(s):
return '(*)' in s
def extract_ptr_type(s):
tokens = s.split()
if tokens[0] == 'const':
return tokens[1]
else:
return tokens[0]
# PREFIX_BLA_BLUB to bla_blub
def as_lower_snake_case(s, prefix):
outp = s.lower()
if outp.startswith(prefix):
outp = outp[len(prefix):]
return outp
# prefix_bla_blub => blaBlub, PREFIX_BLA_BLUB => blaBlub
def as_lower_camel_case(s, prefix):
outp = s.lower()
if outp.startswith(prefix):
outp = outp[len(prefix):]
parts = outp.split('_')
outp = parts[0]
for part in parts[1:]:
outp += part.capitalize()
return outp