package org.greenstone.gsdl3.gs3build.util; public class GS2TextFileHandler { String content; String line; public GS2TextFileHandler(String content) { this.content = content; } public boolean hasMore() { return this.line != null; } public boolean hasMoreLines() { return this.content != null; } public String getEntry() { return this.getEntry(false); } public String getEntry(boolean breakSpace) { String reply; int start, tab = 0; boolean quoted = false; if (!this.hasMore()) { return null; } start = 0; while (start < this.line.length() && this.line.charAt(start) == ' ') { start ++; } if (start == this.line.length()) { this.line = null; return null; } if (this.line.charAt(start) == '"') { quoted = true; breakSpace = false; start ++; } tab = start; while (tab != this.line.length() && this.line.charAt(tab) != '\t' && !(quoted && this.line.charAt(tab) == '"') && !(this.line.charAt(tab) == ' ' && breakSpace)) { tab ++; } if (start > 0) { this.line = this.line.substring(start); tab -= start; } if (tab == this.line.length()) { reply = this.line; this.line = null; } else { reply = this.line.substring(0, tab); this.line = this.line.substring(tab+1); } reply.trim(); return reply; } public String getLine() { if (this.content == null) { this.line = null; return null; } do { int eol = this.content.indexOf('\n'); if (eol < 0) { this.line = this.content; this.content = null; } else { this.line = this.content.substring(0, eol); this.content = this.content.substring(eol+1); while (this.content.length() > 0 && this.content.charAt(0) < ' ') { this.content = this.content.substring(1); } } if (this.line != null) { this.line.trim(); } } while (this.content != null && this.line != null && this.line.length() == 0); return this.line; } }