This repository was archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommentReducer.ts
82 lines (73 loc) · 2.39 KB
/
commentReducer.ts
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
81
82
export function removeComments(contents: string){
const qs=(contents+" ").split("")
const nsl = removeSingleLine(qs)
const nml = removeMultiLine(nsl)
return nml
}
export function removeSingleLine(contents: string[]){
const h = "u3498urt891349f"
let co = 0;
const src = new Array<string>()
let inString = false
while (co!=(contents.length)){
if(contents[co] == '"' && !inString){
src[co] = contents[co]
co++
inString = true
}else if (contents[co] == '"' && inString){
inString = false
}
if (
`${contents[co]}${contents[co+1]}` == "??" && !inString
){
while (contents[co] != '\0' && contents[co] != '\n' && !inString){
if (inString) {break}
if (co+1>(contents.length-1)){break;}else{co++;}
src[co] = h
}
// if (co+1>(qs.length-1)){break;}else{co++;}
}else{
src[co] = contents[co]
if (co+1>(contents.length-1)){break;}else{co++;}
}
}
return src.join("").replaceAll(h, "").split("")
}
export function removeMultiLine(contents: string[]){
const h = "u3498urt891349f"
let co = 0;
const src = new Array<string>()
let inString = false
while (co!=(contents.length)){
if(contents[co] == '"' && !inString){
src[co] = contents[co]
co++
inString = true
}else if (contents[co] == '"' && inString){
inString = false
}
if (
`${contents[co]}${contents[co+1]}` == "-?" && !inString
){
src[co] = h
while (contents[co] != '\0' && !inString){
if (inString) {break}
if (co+1>(contents.length-1)){break;}else{co++;}
if (`${contents[co]}${contents[co+1]}` != "?-"){
src[co] = h
}else{
break
}
}
if (co+1>(contents.length-1)){break;}else{co++;}
src[co+1] = h
if (co+1>(contents.length-1)){break;}else{co++;}
src[co+1] = h
// if (co+1>(qs.length-1)){break;}else{co++;}
}else{
src[co] = contents[co]
if (co+1>(contents.length-1)){break;}else{co++;}
}
}
return src.join("").replaceAll(h, "").split("")
}