internal static CharSequenceAdapter Copy(CharSequenceAdapter other) { CharSequenceAdapter buf = new CharSequenceAdapter(other.sequence); buf.limit = other.limit; buf.position = other.position; buf.mark = other.mark; return(buf); }
public override ICharSequence SubSequence(int start, int end) { if (end < start || start < 0 || end > Remaining) { throw new IndexOutOfRangeException(); } CharSequenceAdapter result = Copy(this); result.position = position + start; result.limit = position + end; return(result); }
/** * Creates a new char buffer by wrapping the given char sequence. * <p> * The new buffer's position will be {@code start}, limit will be * {@code end}, capacity will be the length of the char sequence. The new * buffer is read-only. * * @param chseq * the char sequence which the new buffer will be based on. * @param start * the start index, must not be negative and not greater than * {@code chseq.length()}. * @param end * the end index, must be no less than {@code start} and no * greater than {@code chseq.length()}. * @return the created char buffer. * @exception IndexOutOfBoundsException * if either {@code start} or {@code end} is invalid. */ public static CharBuffer Wrap(ICharSequence chseq, int start, int end) { if (chseq == null) { throw new ArgumentNullException(nameof(chseq)); } if (start < 0 || end < start || end > chseq.Length) { throw new IndexOutOfRangeException(); } CharBuffer result = new CharSequenceAdapter(chseq); result.position = start; result.limit = end; return(result); }