guava/src/com/google/common/escape/UnicodeEscaper.java
protected static int codePointAt(CharSequence seq, int index, int end) {
    checkNotNull(seq);
    if (index < end) {
      char c1 = seq.charAt(index++);
      if (c1 < Character.MIN_HIGH_SURROGATE || c1 > Character.MAX_LOW_SURROGATE) {
        // Fast path (first test is probably all we need to do)
        return c1;
      } else if (c1 <= Character.MAX_HIGH_SURROGATE) {
        // If the high surrogate was the last character, return its inverse
        if (index == end) {
          return -c1;
        }
        // Otherwise look for the low surrogate following it
        char c2 = seq.charAt(index);
        if (Character.isLowSurrogate(c2)) {
          return Character.toCodePoint(c1, c2);
        }
        throw new IllegalArgumentException(
            "Expected low surrogate but got char '"
                + c2
                + "' with value "
                + (int) c2
                + " at index "
                + index
                + " in '"
                + seq
                + "'");
      } else {
        throw new IllegalArgumentException(
            "Unexpected low surrogate character '"
                + c1
                + "' with value "
                + (int) c1
                + " at index "
                + (index - 1)
                + " in '"
                + seq
                + "'");
      }
    }
    throw new IndexOutOfBoundsException("Index exceeds specified range");
  }
protected static int codePointAt(CharSequence seq, int index, int end) {
    checkNotNull(seq);
    if (index < end) {
      char c1 = seq.charAt(index++);
      if (c1 < Character.MIN_HIGH_SURROGATE || c1 > Character.MAX_LOW_SURROGATE) {
        // Fast path (first test is probably all we need to do)
        return c1;
      } else if (c1 <= Character.MAX_HIGH_SURROGATE) {
        // If the high surrogate was the last character, return its inverse
        if (index == end) {
          return -c1;
        }
        // Otherwise look for the low surrogate following it
        char c2 = seq.charAt(index);
        if (Character.isLowSurrogate(c2)) {
          return Character.toCodePoint(c1, c2);
        }
        throw new IllegalArgumentException(
            "Expected low surrogate but got char '"
                + c2
                + "' with value "
                + (int) c2
                + " at index "
                + index
                + " in '"
                + seq
                + "'");
      } else {
        throw new IllegalArgumentException(
            "Unexpected low surrogate character '"
                + c1
                + "' with value "
                + (int) c1
                + " at index "
                + (index - 1)
                + " in '"
                + seq
                + "'");
      }
    }
    throw new IndexOutOfBoundsException("Index exceeds specified range");
  }
Returns the Unicode code point of the character at the given index.

<p>Unlike {@link Character#codePointAt(CharSequence, int)} or {@link String#codePointAt(int)}
this method will never fail silently when encountering an invalid surrogate pair.

<p>The behaviour of this method is as follows:

<ol>
<li>If {@code index >= end}, {@link IndexOutOfBoundsException} is thrown.
<li><b>If the character at the specified index is not a surrogate, it is returned.</b>
<li>If the first character was a high surrogate value, then an attempt is made to read the
next character.
<ol>
<li><b>If the end of the sequence was reached, the negated value of the trailing high
surrogate is returned.</b>
<li><b>If the next character was a valid low surrogate, the code point value of the
high/low surrogate pair is returned.</b>
<li>If the next character was not a low surrogate value, then {@link
IllegalArgumentException} is thrown.
</ol>
<li>If the first character was a low surrogate value, {@link IllegalArgumentException} is
thrown.
</ol>

@param seq the sequence of characters from which to decode the code point
@param index the index of the first character to decode
@param end the index beyond the last valid character to decode
@return the Unicode code point for the given index or the negated value of the trailing high
surrogate character at the end of the sequence