code: @TCB
    private static int longestPrefixOfGoodCodeunits(String s) {
      int n = s.length(), i;
      for (i = 0; i < n; ++i) {
        char ch = s.charAt(i);
        if (ch < 0x20) {
          if (IS_BANNED_ASCII[ch]) {
            return i;
          }
        } else if (0xd800 <= ch) {
          if (ch <= 0xdfff) {
            if (i+1 < n && Character.isSurrogatePair(ch, s.charAt(i+1))) {
              ++i;  // Skip over low surrogate since we know it's ok.
            } else {
              return i;
            }
          } else if ((ch & 0xfffe) == 0xfffe) {
            return i;
          }
        }
      }
      return -1;
    }
docs: The number of code-units at the front of s that form code-points in the
  XML Character production.
  @return -1 if all of s is in the XML Character production.