@@ -60,68 +60,48 @@ func getLastFunction(vbscript *domain.VBScript) *domain.Function {
6060}
6161
6262func isBeginNestStatement (str string ) bool {
63- isIf , err := regexp .MatchString (domain .VBScriptIfPattern , str )
64- if err != nil {
65- fmt .Printf ("err: %v" , err )
66- }
67-
68- isFor , err := regexp .MatchString (domain .VBScriptForPattern , str )
69- if err != nil {
70- fmt .Printf ("err: %v" , err )
63+ patterns := []string {
64+ domain .VBScriptIfPattern ,
65+ domain .VBScriptForPattern ,
66+ domain .VBScriptDoPattern ,
67+ domain .VBScriptWhilePattern ,
68+ domain .VBScriptSelectPattern ,
7169 }
7270
73- isDo , err := regexp .MatchString (domain .VBScriptDoPattern , str )
74- if err != nil {
75- fmt .Printf ("err: %v" , err )
76- }
77-
78- isWhile , err := regexp .MatchString (domain .VBScriptWhilePattern , str )
79- if err != nil {
80- fmt .Printf ("err: %v" , err )
81- }
82-
83- isSelect , err := regexp .MatchString (domain .VBScriptSelectPattern , str )
84- if err != nil {
85- fmt .Printf ("err: %v" , err )
86- }
87-
88- return isIf || isFor || isDo || isWhile || isSelect
71+ return isMatchStatement (str , patterns )
8972}
9073
9174func isEndNestStatement (str string ) bool {
92- isEndIf , err := regexp .MatchString (domain .VBScriptEndIfPattern , str )
93- if err != nil {
94- fmt .Printf ("err: %v" , err )
75+ patterns := []string {
76+ domain .VBScriptEndIfPattern ,
77+ domain .VBScriptNextPattern ,
78+ domain .VBScriptLoopPattern ,
79+ domain .VBScriptWhileEndPattern ,
80+ domain .VBScriptEndSelectPattern ,
9581 }
9682
97- isNext , err := regexp .MatchString (domain .VBScriptNextPattern , str )
98- if err != nil {
99- fmt .Printf ("err: %v" , err )
100- }
101-
102- isLoop , err := regexp .MatchString (domain .VBScriptLoopPattern , str )
103- if err != nil {
104- fmt .Printf ("err: %v" , err )
105- }
106-
107- isWhileEnd , err := regexp .MatchString (domain .VBScriptWhileEndPattern , str )
108- if err != nil {
109- fmt .Printf ("err: %v" , err )
110- }
83+ return isMatchStatement (str , patterns )
84+ }
11185
112- isEndSelect , err := regexp . MatchString ( domain . VBScriptEndSelectPattern , str )
113- if err != nil {
114- fmt . Printf ( "err: %v" , err )
86+ func isIncrementStatement ( str string ) bool {
87+ patterns := [] string {
88+ domain . VBScriptElsePattern ,
11589 }
11690
117- return isEndIf || isNext || isLoop || isWhileEnd || isEndSelect
91+ return isMatchStatement ( str , patterns )
11892}
11993
120- func isIncrementStatement (str string ) bool {
121- isElse , err := regexp .MatchString (domain .VBScriptElsePattern , str )
122- if err != nil {
123- fmt .Printf ("err: %v" , err )
94+ func isMatchStatement (line string , patterns []string ) bool {
95+ for _ , pattern := range patterns {
96+ isMatch , err := regexp .MatchString (pattern , line )
97+ if err != nil {
98+ fmt .Printf ("err: %v" , err )
99+ }
100+
101+ if isMatch {
102+ return true
103+ }
124104 }
125105
126- return isElse
106+ return false
127107}
0 commit comments