             case .unescapedTag(let startIndex, let startLineNumber):
                 if c == "\n" {
                     lineNumber += 1
-                } else if atString(i, currentDelimiters.unescapedTagEnd) {
+                } else if index(i, isAt: currentDelimiters.unescapedTagEnd, in: templateString) {
                     let tagInitialIndex = templateString.index(startIndex, offsetBy: currentDelimiters.unescapedTagStartLength)
                     let content = String(templateString[tagInitialIndex..<i])
                     let token = TemplateToken(

            case .tag(let startIndex, let startLineNumber):
                if c == "\n" {
                    lineNumber += 1
                } else if atString(i, currentDelimiters.tagDelimiterPair.1) {
                    let tagInitialIndex = templateString.index(startIndex, offsetBy: currentDelimiters.tagStartLength)
                    let tagInitial = templateString[tagInitialIndex]
                    let tokenRange = startIndex..<templateString.index(i, offsetBy: currentDelimiters.tagEndLength)

                if c == "\n" {
                    state = .text(startIndex: i, startLineNumber: lineNumber)
                    lineNumber += 1
                } else if index(i, isAt: currentDelimiters.unescapedTagStart, in: templateString) {
                    state = .unescapedTag(startIndex: i, startLineNumber: lineNumber)
                    i = templateString.index(i, offsetBy: currentDelimiters.unescapedTagStartLength)
                    i = templateString.index(before: i)
                } else if index(i, isAt: currentDelimiters.setDelimitersStart, in: templateString) {
                    state = .setDelimitersTag(startIndex: i, startLineNumber: lineNumber)
                    i = templateString.index(i, offsetBy: currentDelimiters.setDelimitersStartLength)
                    i = templateString.index(before: i)
                } else if index(i, isAt: currentDelimiters.tagDelimiterPair.0, in: templateString) {
                    state = .tag(startIndex: i, startLineNumber: lineNumber)
                    i = templateString.index(i, offsetBy: currentDelimiters.tagStartLength)
                    i = templateString.index(before: i)
