Search in sources :

Example 6 with CharSequenceReader

use of org.eclipse.wst.sse.core.internal.text.CharSequenceReader in project webtools.sourceediting by eclipse.

the class TestCharSequenceReader method testBufferEndEnlarged.

public void testBufferEndEnlarged() throws IOException {
    CharSequenceReader reader = new CharSequenceReader(fStandardString, 4, 3);
    String targetString = "123";
    // intentionally small sized buffer
    char[] charbuffer = new char[200];
    StringBuffer stringBuffer = new StringBuffer();
    int nRead = 0;
    while (nRead != -1) {
        nRead = reader.read(charbuffer);
        if (nRead > 0) {
            stringBuffer.append(charbuffer, 0, nRead);
        }
    }
    String testString = stringBuffer.toString();
    assertEquals(targetString, testString);
}
Also used : CharSequenceReader(org.eclipse.wst.sse.core.internal.text.CharSequenceReader)

Example 7 with CharSequenceReader

use of org.eclipse.wst.sse.core.internal.text.CharSequenceReader in project webtools.sourceediting by eclipse.

the class TestCharSequenceReader method testBufferBeginingReduced.

public void testBufferBeginingReduced() throws IOException {
    CharSequenceReader reader = new CharSequenceReader(fStandardString, 0, 3);
    String targetString = "te";
    // intentionally small sized buffer
    char[] charbuffer = new char[2];
    StringBuffer stringBuffer = new StringBuffer();
    int nRead = 0;
    // while (nRead != -1) {
    nRead = reader.read(charbuffer, 0, 2);
    if (nRead > 0) {
        stringBuffer.append(charbuffer, 0, nRead);
    }
    // }
    String testString = stringBuffer.toString();
    assertEquals(targetString, testString);
    // / now continue reading same reader
    targetString = "s";
    stringBuffer = new StringBuffer();
    nRead = 0;
    // while (nRead != -1) {
    nRead = reader.read(charbuffer, 0, 2);
    if (nRead > 0) {
        stringBuffer.append(charbuffer, 0, nRead);
    }
    // }
    testString = stringBuffer.toString();
    assertEquals(targetString, testString);
}
Also used : CharSequenceReader(org.eclipse.wst.sse.core.internal.text.CharSequenceReader)

Example 8 with CharSequenceReader

use of org.eclipse.wst.sse.core.internal.text.CharSequenceReader in project webtools.sourceediting by eclipse.

the class XMLSourceParser method reset.

/**
 * Resets the input.
 */
public void reset(java.io.Reader reader, int position) {
    primReset();
    fOffset = position;
    getTokenizer().reset(reader, position);
    if (reader instanceof DocumentReader) {
        IDocument doc = ((DocumentReader) reader).getDocument();
        if (doc instanceof CharSequence) {
            fCharSequenceSource = (CharSequence) doc;
        } else {
            // old fashioned IDocument
            fDocumentInput = ((DocumentReader) reader).getDocument();
        }
    } else if (reader instanceof CharSequenceReader) {
        fCharSequenceSource = ((CharSequenceReader) reader).getOriginalSource();
    }
}
Also used : CharSequenceReader(org.eclipse.wst.sse.core.internal.text.CharSequenceReader) DocumentReader(org.eclipse.wst.sse.core.internal.document.DocumentReader) IDocument(org.eclipse.jface.text.IDocument)

Example 9 with CharSequenceReader

use of org.eclipse.wst.sse.core.internal.text.CharSequenceReader in project webtools.sourceediting by eclipse.

the class TestCharSequenceReader method testBufferBeginingEnlarged.

public void testBufferBeginingEnlarged() throws IOException {
    CharSequenceReader reader = new CharSequenceReader(fStandardString, 0, 3);
    String targetString = "tes";
    // intentionally small sized buffer
    char[] charbuffer = new char[200];
    StringBuffer stringBuffer = new StringBuffer();
    int nRead = 0;
    while (nRead != -1) {
        nRead = reader.read(charbuffer);
        if (nRead > 0) {
            stringBuffer.append(charbuffer, 0, nRead);
        }
    }
    String testString = stringBuffer.toString();
    assertEquals(targetString, testString);
}
Also used : CharSequenceReader(org.eclipse.wst.sse.core.internal.text.CharSequenceReader)

Example 10 with CharSequenceReader

use of org.eclipse.wst.sse.core.internal.text.CharSequenceReader in project webtools.sourceediting by eclipse.

the class TestCharSequenceReader method testStandardPartiallyOutOfRange.

public void testStandardPartiallyOutOfRange() {
    CharSequenceReader reader = new CharSequenceReader(fStandardString, 5, 3);
    char char1 = (char) reader.read();
    assertTrue(char1 == '2');
    char char2 = (char) reader.read();
    assertTrue(char2 == '3');
    int eof = reader.read();
    assertTrue(eof == -1);
}
Also used : CharSequenceReader(org.eclipse.wst.sse.core.internal.text.CharSequenceReader)

Aggregations

CharSequenceReader (org.eclipse.wst.sse.core.internal.text.CharSequenceReader)11 IDocument (org.eclipse.jface.text.IDocument)1 DocumentReader (org.eclipse.wst.sse.core.internal.document.DocumentReader)1