docs: public static int getANSIControlSequenceLength(String string, int index) {
          int len = 0, restlen = string.length() - index;
          if (restlen >= 3) { // Control sequences require a minimum of three characters
              char esc = string.charAt(index),
                   bracket = string.charAt(index+1);
              if (esc == 0x1B && bracket == '[') { // escape & open bracket
                  len = 3; // esc,bracket and (later)terminator.
                  //  digits or semicolons can still precede the terminator:
                  for (int i = 2; i < restlen; i++) {
                      char ch = string.charAt(i + index);
                      // only ascii-digits or semicolons allowed here:
                      if ( (ch >= '0' && ch <= '9') || ch == ';') {
                          len++;
                      } else {
                          break;
                      }
                  }
                  // if string ends in digits/semicolons, then it's not a sequence.
                  if (len > restlen) {
                      len = 0;
                  }
              }
          }
          return len;
      }