MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / ReadLineNoComment

Function ReadLineNoComment

opensca/model/file.go:113–162  ·  view source on GitHub ↗

ReadLineNoComment 按行读取内容 忽略注释

(reader io.Reader, t *CommentType, do func(line string))

Source from the content-addressed store, hash-verified

111
112// ReadLineNoComment 按行读取内容 忽略注释
113func ReadLineNoComment(reader io.Reader, t *CommentType, do func(line string)) {
114
115 if do == nil {
116 return
117 }
118
119 if t == nil {
120 t = CTypeComment
121 }
122
123 // 标记当前是非位于多行注释段
124 comment := false
125
126 ReadLine(reader, func(line string) {
127
128 // 单行注释
129 if t.Simple != "" {
130 i := strings.Index(line, t.Simple)
131 if i != -1 {
132 line = line[:i]
133 }
134 }
135
136 // 多行注释
137 if t.Begin != "" && t.End != "" {
138 for {
139 // 当前非注释段且存在注释起始标记
140 if start_i := strings.Index(line, t.Begin); !comment && start_i != -1 {
141 comment = true
142 do(line[:start_i])
143 line = line[start_i+len(t.Begin):]
144 continue
145 }
146 // 当前为注释段且存在注释终止标记
147 if end_i := strings.Index(line, t.End); comment && end_i != -1 {
148 comment = false
149 line = line[end_i+len(t.End):]
150 continue
151 }
152 break
153 }
154 if comment {
155 return
156 }
157 }
158
159 do(line)
160 })
161
162}
163
164// ResCallback 检测结果回调函数
165// file: 检出组件的文件信息

Callers 2

ParseSetupFunction · 0.92
ReadLineNoCommentMethod · 0.85

Calls 2

ReadLineFunction · 0.85
IndexMethod · 0.80

Tested by

no test coverage detected