All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openpdf.renderer.function.postscript.PostScriptParser Maven / Gradle / Ivy

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