//-------------------------------------------------------------------------------------------------- // // @ CopyRight Roberti & Parau Enterprises, Inc. 2021-2023 // // This work is licensed under the Creative Commons Attribution-NoDerivatives 4.0 International License. // To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/4.0/ // or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. // //-------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------- // // Class to manage a single string input to JAVACC parser // //-------------------------------------------------------------------------------------------------- package framework; import java.io.InputStream; public class DVInputString extends InputStream { // // Create class // public DVInputString(String inputString) { this.inputStream= inputString.getBytes(); } // // Input stream methods // public int read() { if (this.index >= this.inputStream.length) return -1; int ret= this.inputStream[this.index]; this.index++; return ret; } public int read(byte[] buffer, int offset, int length) { if (this.index >= this.inputStream.length) return -1; int copyLength; for (copyLength= offset; copyLength < offset+length && this.index < this.inputStream.length; copyLength++) { buffer[copyLength]= this.inputStream[this.index]; this.index++; } return copyLength-offset; } public boolean markSupported() { return true; } public void mark(int inputLimit) { this.markIndex= this.index; } public void reset() { this.index= this.markIndex; } // // Class fields // private byte[] inputStream; private int index= 0; private int markIndex= -1; }