function hasBalancedSquareBrackets(value) {
  let outside = true;
  const tokenRe = /^[-_a-zA-Z0-9]$/;
  for (let i = 0; i < value.length; i++) {
    const c = value.charAt(i);
    if (c == ']') {
      if (outside) return false;  // Unbalanced ].
      outside = true;
    } else if (c == '[') {
      if (!outside) return false;  // No nesting.
      outside = false;
    } else if (!outside && !tokenRe.test(c)) {
      return false;
    }
  }
  return outside;
}
Checks that square brackets ([ and ]) are properly balanced inside a string,
and that the content in the square brackets is one ident-token;
see https://www.w3.org/TR/css-syntax-3/#ident-token-diagram.
For practicality, and in line with other restrictions posed on SafeStyle
strings, we restrict the character set allowable in the ident-token to
[-_a-zA-Z0-9].
@param {string} value Untrusted CSS property value.
@return {boolean} True if property value is safe with respect to square
    bracket balancedness.