org.snapscript.common.io.PropertyReader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of snap Show documentation
Show all versions of snap Show documentation
Dynamic scripting for the JVM
package org.snapscript.common.io;
public abstract class PropertyReader extends StatementReader {
protected PropertyReader(String file) {
super(file);
}
@Override
protected T create(char[] data, int off, int length, int line) {
int seek = 0;
while(seek < length) {
char next = data[off + seek++];
if(separator(next)) {
String name = format(data, off, seek - 1);
if(seek >= length) {
throw new StatementException("No value in '" + file + "' at line " + line);
}
return create(name, data, off + seek, length - seek, line);
}
}
throw new StatementException("Error in '" + file + "' at line " + line);
}
protected String format(char[] data, int off, int length) {
int finish = off + length;
int start = off;
while(start < finish) {
char next = data[start];
if(!space(next)) {
break;
}
start++;
}
while(finish > start) {
char next = data[finish-1];
if(!space(next)) {
break;
}
finish--;
}
return new String(data, start, finish -start);
}
protected boolean separator(char value) {
return value == '=';
}
protected abstract T create(String name, char[] data, int off, int length, int line);
}