-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-reflect.html
67 lines (48 loc) · 1.73 KB
/
auto-reflect.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
67
<html>
<h1>Automatically Generate QtJson Registration Text</h1>
<p>Copy the class member types and member names directly into the input box, click Convert, and the registration text will be output: REFLECT(a,b,c)</p>
<div >
input:<textarea id="inputStr" rows="20" cols="100" placeholder=" double totalGb;
double usedGb;
double freeGb ;
double usedPercentage;
double freePercentage;"></textarea>
<button id="trans" onclick="transfer()">registration</button>
</div>
<div>
output:<textarea id="outputStr" rows="10" cols="100" placeholder="REFLECT(totalGb,usedGb,usedPercentage,freePercentage)"></textarea>
</div>
<script >
let inputTextarea = document.getElementById("inputStr");
let outputTextarea = document.getElementById("outputStr");
function extractVariableNames(str) {
// 正则表达式用于匹配变量名
// 匹配变量名,忽略初始值和注释
const regex = /(\w+)\s*=\s*[^;]*;|(\w+);\s*(?![^\/]*\/\*[^\/]*\*\/)/g;
let match;
let variableNames = [];
// 使用正则表达式匹配每一行中的变量名
while ((match = regex.exec(str)) !== null) {
// 提取变量名并添加到数组中
if (match[1]) {
variableNames.push(match[1]);
} else if (match[2]) {
variableNames.push(match[2]);
}
}
// 将变量名数组转换为逗号分隔的字符串
return variableNames.join(',');
}
function transfer(){
console.log(inputTextarea.value.length);
if(inputTextarea.value.length>0){
// 调用函数并打印结果
let result = extractVariableNames(inputTextarea.value);
console.log(result);
outputTextarea.value = `REFLECT(${result})`;
}else{
alert("plese input text");
}
}
</script>
</html>