Skip to content

Commit

Permalink
corrent the escape character judge
Browse files Browse the repository at this point in the history
  • Loading branch information
foxdd committed Apr 18, 2021
1 parent a663333 commit 1474c8b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion processor/state_string.go
Expand Up @@ -22,7 +22,7 @@ func (state *StateString) Process(job *FileJob, lang *LanguageFeature, index int
}

// If we are in a literal string we want to ignore the \ check OR we aren't checking for special ones
if state.SkipEsc || job.Content[i-1] != '\\' {
if state.SkipEsc || judgeEscape(i, job) {
if checkForMatchSingle(job.Content[i], i, job.EndPoint, state.End, job) {
return i, LINE_CODE, &StateCode{}
}
Expand All @@ -35,3 +35,14 @@ func (state *StateString) Process(job *FileJob, lang *LanguageFeature, index int
func (state *StateString) Reset() (LineType, State) {
return LINE_CODE, state
}

// judge if the slash count before index is even number
func judgeEscape(index int, fileJob *FileJob) bool {
slashCount := 0
i := 1
for index >= i && fileJob.Content[index-i] == '\\' {
slashCount++
i++
}
return slashCount%2 == 0
}

0 comments on commit 1474c8b

Please sign in to comment.