/** * Creates a {@linkplain Source Source instance} that represents the contents of a sub-range of * an <code>this</code> {@link Source}. * * @param baseCharIndex 0-based index of the first character of the sub-range * @param length the number of characters in the sub-range * @return a new instance representing a sub-range of another Source * @throws IllegalArgumentException if the specified sub-range is not contained in the base * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @since 0.15 */ public Source subSource(int baseCharIndex, int length) { if (hasBytes()) { throw new UnsupportedOperationException("Operation is only enabled for character based sources."); } CompilerAsserts.neverPartOfCompilation(NO_FASTPATH_SUBSOURCE_CREATION_MESSAGE); return SubSourceImpl.create(this, baseCharIndex, length); }
/** * Creates a {@linkplain Source Source instance} that represents the contents of a sub-range of * an <code>this</code> {@link Source}. * * @param baseCharIndex 0-based index of the first character of the sub-range * @param length the number of characters in the sub-range * @return a new instance representing a sub-range of another Source * @throws IllegalArgumentException if the specified sub-range is not contained in the base * @since 0.15 */ public Source subSource(int baseCharIndex, int length) { SourceAccessor.neverPartOfCompilation(NO_FASTPATH_SUBSOURCE_CREATION_MESSAGE); final SubSourceImpl subSource = SubSourceImpl.create(this, baseCharIndex, length); return new SourceImpl(subSource); }