public static CharSequence withoutSubSequence(CharSequence input, int beginIndex, int endIndex) {
    if (input == null) throw new NullPointerException("input == null");
    int length = input.length();

    // Exit early if the region is empty or the entire input
    int skippedRegionLength = regionLength(length, beginIndex, endIndex);
    if (skippedRegionLength == 0) return input;
    if (beginIndex == 0 && endIndex == length) return "";

    // Exit early if the region ends on a boundary.
    // This doesn't use input.subsequence as it might allocate a String
    if (beginIndex == 0) return new SubSequence(input, endIndex, length);
    if (endIndex == length) return new SubSequence(input, 0, beginIndex);

    // Otherwise, the region to skip in the middle
    return new WithoutSubSequence(input, 0, beginIndex, endIndex, length);
  }
@Test void withoutSubSequence_length() {
    String input = "b3=1,es=2";

    for (CharSequence sequence : asList(
      CharSequences.withoutSubSequence(input, 0, 2),
      CharSequences.withoutSubSequence(input, 2, 4),
      CharSequences.withoutSubSequence(input, 4, 6),
      CharSequences.withoutSubSequence(input, 6, 8),
      CharSequences.withoutSubSequence(input, 1, 9),
      CharSequences.withoutSubSequence(input, 0, 8))) {
      String string = sequence.toString(); // we know this is ok as it is tested above
      assertThat(sequence.length()).isEqualTo(string.length());
    }
  }