-
Notifications
You must be signed in to change notification settings - Fork 207
/
codeGenerator.html
66 lines (63 loc) · 1.82 KB
/
codeGenerator.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="generator" content="iptton#gmail.com"/>
<title>c++ .h define to declare</title>
</head>
<body>
<textarea id="defines" style="width:300px;height:200px">
public:
void
a();
void *b()const;
const a* b():const;
const a& c():const;
signals:
void k();
private:
void d(d& c,C c=3):const;
signals:
void k();
</textarea>
<textArea id="output" style="width:300px;height:200px">
</textArea><br/>
<label for="className">class name</label><input type="text" id="className" /> <br/>
<label for="useSpace">use space instead of tab</label><input type="checkBox" checked /><br/>
<label for="tabWidth">tab width</label><input type="text" value="4" id="tabWidth"/>
<button id="go">go</button>
<script>
function $(id){return document.getElementById(id);}
$('go').onclick=function(){
s = $('defines').value;
s=s.replace(/[\n]/g,"");
s=s.replace(/[\t]/g,"");
//console.info(s);
s = s.trim();
s = s.replace(/[\s]{2,}/g," ");
//console.info(s);
s=s.replace(/signals\:.*(?:((private|public|protected)))/g,"");//replace all signals
s=s.replace(/signals\:.*$/g,"");//replace all signals
s=s.replace(/((public)|(private)|(protected))\:/g,"");
fs = s.split(";");
var className=$('className').value;
var outputStr=[];
for(var i=0;i<fs.length;++i){
var f = fs[i];
f=f.trim();
if(!f)continue;
//console.info(f);
var j = f.search(/[^\s]+\(/); // bala bala fName(argType arg1,argType2 arg2...):const;
if(j==-1){
outputStr.push("/*invalid function:",f,"*/");
continue;
}
var type=f.substr(0,j);
var fnameAndArg=f.substr(j,f.length-1-j);
outputStr.push([type,className,"::",fnameAndArg,"{\\TODO auto generator by ippan\r\n\r\n}"].join(""));
}
$('output').value=outputStr.join("\r\n");
$('output').select();
}
</script>
</body>
</html>