55 lines
1.2 KiB
Plaintext
55 lines
1.2 KiB
Plaintext
package slangc.sdk;
|
|
|
|
import slangc.streams.FileInput;
|
|
import slangc.streams.File;
|
|
import slangc.parser.Source;
|
|
|
|
public class SimpleSource extends Source {
|
|
byte[] source;
|
|
|
|
public SimpleSource(File file) throws Error {
|
|
this(file.path(), file);
|
|
}
|
|
|
|
public SimpleSource(String filename, File file) throws Error {
|
|
super(filename);
|
|
FileInput is = file.openInput();
|
|
byte[] fileData = new byte[(int) file.size()];
|
|
/*int i =*/ is.read(fileData);
|
|
//System.out.println("Read " + i + " bytes from " + file);
|
|
is.close();
|
|
this.source = String.construct(fileData);
|
|
//sourceFile = this.source.replace("\r\n", "\n");
|
|
//System.out.println("GOT:\n" + sourceFile);
|
|
}
|
|
|
|
public SimpleSource(String filename, String source) {
|
|
super(filename);
|
|
this.source = source;
|
|
}
|
|
|
|
public SimpleSource(String source) {
|
|
this.source = source;
|
|
}
|
|
|
|
@Override
|
|
public int getIndexLength() {
|
|
return source.length;
|
|
}
|
|
|
|
@Override
|
|
public int getCharacter(int index) {
|
|
if (isIndexWithinBounds(index)) {
|
|
return (int) source[index]; //.charAt(index);
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getNextIndex(int currentIndex) {
|
|
// TODO Auto-generated method stub
|
|
return currentIndex + 1;
|
|
}
|
|
}
|