fix($interpolate): use the first end symbol that forms a valid expression

When an interpolation string has multiple end symbol choices, pick the
occurrence that forms a valid expression

Closes #8642
This was kind of a hard read, I think I would refactor this to something like:

```js
var brackets = [[0, 0, 0], [0, 0, 0]], bracketChars = '({[)}]', ch, quoteCh;
index = startIndex + startSymbolLength;
while (index !== endIndex || quoteCh || !equals(brackets[0], brackets[1])) {
  if (index === endIndex) {
    endIndex = text.indexOf(endSymbol, endIndex + 1);
    if (endIndex === -1) {
      break;
    }
  }
  ch = text[index];
  if (quoteCh) {
    if (ch === '\\') {
      index++;
    } else if (ch === quoteCh) {
      quoteCh = undefined;
    }
  } else if (ch === "'" || ch === '"') {
    quoteCh = ch;
  } else if ((i = bracketChars.indexOf(ch)) != -1) {
    brackets[i/3][i%3]++;
  }
  index++;
}
```
(haven't tested, I might have some bug there)