diff --git a/processor/state_string.go b/processor/state_string.go index 91194e08..93d901cc 100644 --- a/processor/state_string.go +++ b/processor/state_string.go @@ -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{} } @@ -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 +}