-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamel_case_matcher.py
80 lines (56 loc) · 1.63 KB
/
camel_case_matcher.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
l = ["Hello", "World" "HelloMars", "HelloWorld", "HelloWorldMars", "HiHo"]
patterns = ["H", "He", "HeW", "HeWo", "HeWor", "HeWorM"]
# patterns = ["H", "HW", "Ho", "HeWorM", "He"]
d = {
"HelloMars": ["Hello", "Mars"],
"HelloWorld": ["Hello", "World"],
"HelloWorldMars": ["Hello", "World", "Mars"],
"HiHo": ["Hi", "Ho"]
}
def split_camel_case(word):
result = []
start = 0
for i in range(1, len(word)):
if word[i].isupper():
result.append(word[start:i])
start = i
result.append(word[start:])
return result
# for word in l:
# print split_camel_case(word)
print '-----------'
pat = "HeWorM"
# print split_camel_case(pat)
def generate_splitetd_dict(l):
result = {}
for word in l:
result[word] = split_camel_case(word)
return result
# print generate_splitetd_dict(l)
def get_classes(p, l):
pl = split_camel_case(p)
spl_d = generate_splitetd_dict(l)
for i in range(len(pl)):
for k, v in spl_d.items():
approved = False
for w_i in range(i, len(v)):
if v[w_i].startswith(pl[i]):
approved = True
if not approved:
del spl_d[k]
return spl_d.keys()
for pattern in patterns:
print pattern, get_classes(pattern, l)
def word_mut(word):
result = []
for i in range(len(word)):
result.append(word[:i + 1])
return result
def get_all_patterns(clazz):
words = split_camel_case(clazz)
result = []
for word in words:
result.append(word_mut(word))
return result
print "---------"
print get_all_patterns("HelloWorldMars")