xl-project/app/src/main/java/xl/model/XLBufferedReader.java
2024-06-05 21:37:44 +02:00

42 lines
1.2 KiB
Java

package xl.model;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Map;
import xl.expr.Expr;
import xl.expr.ExprParser;
import xl.util.XLException;
/**
* Specialized BufferedReader for reading XL files.
*/
public class XLBufferedReader extends BufferedReader {
public XLBufferedReader(String name) throws FileNotFoundException {
super(new FileReader(name));
}
public void load(Map<String, Cell> map) {
try {
while (ready()) {
String string = readLine();
int i = string.indexOf('=');
String address = string.substring(0, i);
String content = string.substring(i + 1);
if(content.startsWith("#")){
map.put(address, new CommentCell(content.substring(1)));
} else {
ExprParser parser = new ExprParser();
Expr expression = parser.build(content);
map.put(address, new ExpressionCell(expression));
}
}
} catch (Exception e) {
throw new XLException(e.getMessage());
}
}
}