Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion embedding/commentfilter/visual_basic_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func filterVisualBasicLine(line string, mode Mode) (string, bool) {
var result strings.Builder
position := 0
for position < len(line) {
if quoteEnd := quotedSegmentEnd(line, position, "\""); quoteEnd > position {
if quoteEnd := visualBasicQuotedSegmentEnd(line, position); quoteEnd > position {
result.WriteString(line[position:quoteEnd])
position = quoteEnd

Expand All @@ -87,6 +87,30 @@ func filterVisualBasicLine(line string, mode Mode) (string, bool) {
return result.String(), false
}

// visualBasicQuotedSegmentEnd returns the end offset of a Visual Basic quoted string.
func visualBasicQuotedSegmentEnd(line string, position int) int {
if position >= len(line) || line[position] != '"' {
return position
}
cursor := position + 1
for cursor < len(line) {
if line[cursor] != '"' {
cursor++

continue
}
if cursor+1 < len(line) && line[cursor+1] == '"' {
cursor += 2

continue
}

return cursor + 1
}

return len(line)
}

// remCommentAt reports whether a Visual Basic REM comment starts at position.
func remCommentAt(line string, position int) bool {
if len(line[position:]) < len(rem) ||
Expand Down
6 changes: 6 additions & 0 deletions embedding/commentfilter/visual_basic_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ var _ = Describe("Visual Basic", func() {
"' file comment",
"REM module comment",
"Dim text = \"REM not a comment\"",
"Dim quotedRem = \"\"\"REM not a comment\"",
"Dim quotedApostrophe = \"\"\"' not a comment\"",
"Dim escapedQuote = \"Say \"\"REM\"\" and keep going\" ' inline",
"Dim value = 1 ' inline",
"Dim ready = True : Rem after statement separator",
"Dim reminder = 1",
}

expected := []string{
"Dim text = \"REM not a comment\"",
"Dim quotedRem = \"\"\"REM not a comment\"",
"Dim quotedApostrophe = \"\"\"' not a comment\"",
"Dim escapedQuote = \"Say \"\"REM\"\" and keep going\" ",
"Dim value = 1 ",
"Dim ready = True : ",
"Dim reminder = 1",
Expand Down
Loading