-
Notifications
You must be signed in to change notification settings - Fork 0
/
RemoveComments.go
47 lines (38 loc) · 945 Bytes
/
RemoveComments.go
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
// =================================================================
//
// Copyright (C) 2019 Spatial Current, Inc. - All Rights Reserved
// Released as open source under the MIT License. See LICENSE file.
//
// =================================================================
package dfl
// RemoveComments removes comments from a multi-line dfl expression
func RemoveComments(in string) string {
out := ""
singlequotes := 0
doublequotes := 0
comment := 0
for _, c := range in {
if comment == 0 {
if singlequotes == 0 && doublequotes == 0 {
if c == '"' {
doublequotes += 1
} else if c == '\'' {
singlequotes += 1
} else if c == '#' {
comment += 1
}
} else if doublequotes == 1 && c == '"' {
doublequotes -= 1
} else if singlequotes == 1 && c == '\'' {
singlequotes -= 1
}
if comment == 0 {
out += string(c)
}
}
if c == '\n' {
comment = 0
}
}
return out
}