
org.openpdf.renderer.function.postscript.PostScriptParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openpdf-renderer Show documentation
Show all versions of openpdf-renderer Show documentation
PDF renderer implementation supporting the subset of PDF 1.4 specification.
The newest version!
package org.openpdf.renderer.function.postscript;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
/*****************************************************************************
* Very simple post script parser / tokenizer
*
* @author Bernd Rosstauscher
* @since 22.10.2010
****************************************************************************/
public class PostScriptParser {
/*************************************************************************
* Constructor
************************************************************************/
public PostScriptParser() {
super();
}
/*************************************************************************
* Parses the given script and returns a list of tokens.
* @param scriptContent to parse.
* @return the list of tokens.
************************************************************************/
public List parse(String scriptContent) {
List tokens = new LinkedList();
StringTokenizer tok = new StringTokenizer(scriptContent, " \t\n\r");
while (tok.hasMoreTokens()) {
String t = tok.nextToken();
t = filterBlockStart(t);
t = filterBlockEnd(t);
if (t.length() > 0) {
tokens.add(t.trim());
}
}
return tokens;
}
/*************************************************************************
* @param t
* @return
************************************************************************/
private String filterBlockEnd(String t) {
if (t.endsWith("}")) {
t = t.substring(0, t.length()-1);
}
return t;
}
/*************************************************************************
* @param t
* @return
************************************************************************/
private String filterBlockStart(String t) {
if (t.startsWith("{")) {
t = t.substring(1);
}
return t;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy