// Path: segment/src/main/java/net/loomchild/segment/srx/SrxDocument.java
// public class SrxDocument {
// 
// 	/**
// 	 * Default cascade value.
// 	 */
// 	public static final boolean DEFAULT_CASCADE = true;
// 
// 	private boolean cascade;
// 
// 	private List<LanguageMap> languageMapList;
// 	
// 	private SrxDocumentCache cache;
// 
// 	/**
// 	 * Creates empty document.
// 	 * 
// 	 * @param cascade true if document is cascading
// 	 */
// 	public SrxDocument(boolean cascade) {
// 		this.cascade = cascade;
// 		this.languageMapList = new ArrayList<LanguageMap>();
// 		this.cache = new SrxDocumentCache();
// 	}
// 
// 	/**
// 	 * Creates empty document with default cascade. See {@link #DEFAULT_CASCADE}.
// 	 */
// 	public SrxDocument() {
// 		this(DEFAULT_CASCADE);
// 	}
// 
// 	/**
// 	 * Sets if document is cascading or not.
// 	 * 
// 	 * @param cascade true f document is cascading
// 	 */
// 	public void setCascade(boolean cascade) {
// 		this.cascade = cascade;
// 	}
// 
// 	/**
// 	 * @return true if document is cascading
// 	 */
// 	public boolean getCascade() {
// 		return cascade;
// 	}
// 
// 	/**
// 	 * Add language map to this document.
// 	 * 
// 	 * @param pattern language code pattern
// 	 * @param languageRule
// 	 */
// 	public void addLanguageMap(String pattern, LanguageRule languageRule) {
// 		LanguageMap languageMap = new LanguageMap(pattern, languageRule);
// 		languageMapList.add(languageMap);
// 	}
// 
// 	public List<LanguageMap> getLanguageMapList() {
// 		return languageMapList;
// 	}	
// 
// 	/**
// 	 * If cascade is true then returns all language rules matching given
// 	 * language code. If cascade is false returns first language rule matching
// 	 * given language code. If no matching language rules are found returns
// 	 * empty list.
// 	 * 
// 	 * @param languageCode language code, for example en_US
// 	 * @return matching language rules
// 	 */
// 	public List<LanguageRule> getLanguageRuleList(String languageCode) {
// 		List<LanguageRule> matchingLanguageRuleList = new ArrayList<LanguageRule>();
// 		for (LanguageMap languageMap : languageMapList) {
// 			if (languageMap.matches(languageCode)) {
// 				matchingLanguageRuleList.add(languageMap.getLanguageRule());
// 				if (!cascade) {
// 					break;
// 				}
// 			}
// 		}
// 		return matchingLanguageRuleList;
// 	}
// 
// 	public SrxDocumentCache getCache() {
// 		return cache;
// 	}
// 	
// }


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import net.loomchild.segment.srx.SrxDocument;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

		return patternBuilder.toString();
	}

	/**
	 * Changes unlimited length pattern to limited length pattern. It is done by
	 * replacing constructs with "*" and "+" symbols with their finite 
	 * counterparts - "{0,n}" and {1,n}. 
	 * As a side effect block quotes are replaced with normal quotes
	 * by using {@link #removeBlockQuotes(String)}.
	 * 
	 * @param pattern pattern to be finitized
	 * @param infinity "n" number
	 * @return limited length pattern
	 */
	public static String finitize(String pattern, int infinity) {
		String finitePattern = removeBlockQuotes(pattern);
		
		Matcher starMatcher = STAR_PATTERN.matcher(finitePattern);
		finitePattern = starMatcher.replaceAll("{0," + infinity + "}");
		
		Matcher plusMatcher = PLUS_PATTERN.matcher(finitePattern);
		finitePattern = plusMatcher.replaceAll("{1," + infinity + "}");
		
		Matcher rangeMatcher = RANGE_PATTERN.matcher(finitePattern);
		finitePattern = rangeMatcher.replaceAll("{$1," + infinity + "}");
		
		return finitePattern;
	}

// Path: segment/src/main/java/net/loomchild/segment/srx/SrxDocument.java
// public class SrxDocument {
// 
// 	/**
// 	 * Default cascade value.
// 	 */
// 	public static final boolean DEFAULT_CASCADE = true;
// 
// 	private boolean cascade;
// 
// 	private List<LanguageMap> languageMapList;
// 	
// 	private SrxDocumentCache cache;
// 
// 	/**
// 	 * Creates empty document.
// 	 * 
// 	 * @param cascade true if document is cascading
// 	 */
// 	public SrxDocument(boolean cascade) {
// 		this.cascade = cascade;
// 		this.languageMapList = new ArrayList<LanguageMap>();
// 		this.cache = new SrxDocumentCache();
// 	}
// 
// 	/**
// 	 * Creates empty document with default cascade. See {@link #DEFAULT_CASCADE}.
// 	 */
// 	public SrxDocument() {
// 		this(DEFAULT_CASCADE);
// 	}
// 
// 	/**
// 	 * Sets if document is cascading or not.
// 	 * 
// 	 * @param cascade true f document is cascading
// 	 */
// 	public void setCascade(boolean cascade) {
// 		this.cascade = cascade;
// 	}
// 
// 	/**
// 	 * @return true if document is cascading
// 	 */
// 	public boolean getCascade() {
// 		return cascade;
// 	}
// 
// 	/**
// 	 * Add language map to this document.
// 	 * 
// 	 * @param pattern language code pattern
// 	 * @param languageRule
// 	 */
// 	public void addLanguageMap(String pattern, LanguageRule languageRule) {
// 		LanguageMap languageMap = new LanguageMap(pattern, languageRule);
// 		languageMapList.add(languageMap);
// 	}
// 
// 	public List<LanguageMap> getLanguageMapList() {
// 		return languageMapList;
// 	}	
// 
// 	/**
// 	 * If cascade is true then returns all language rules matching given
// 	 * language code. If cascade is false returns first language rule matching
// 	 * given language code. If no matching language rules are found returns
// 	 * empty list.
// 	 * 
// 	 * @param languageCode language code, for example en_US
// 	 * @return matching language rules
// 	 */
// 	public List<LanguageRule> getLanguageRuleList(String languageCode) {
// 		List<LanguageRule> matchingLanguageRuleList = new ArrayList<LanguageRule>();
// 		for (LanguageMap languageMap : languageMapList) {
// 			if (languageMap.matches(languageCode)) {
// 				matchingLanguageRuleList.add(languageMap.getLanguageRule());
// 				if (!cascade) {
// 					break;
// 				}
// 			}
// 		}
// 		return matchingLanguageRuleList;
// 	}
// 
// 	public SrxDocumentCache getCache() {
// 		return cache;
// 	}
// 	
// }


// Path: segment/src/main/java/net/loomchild/segment/util/Util.java
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.net.URL;
import java.util.Collections;
import java.util.Map;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import net.loomchild.segment.srx.SrxDocument;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;


		return patternBuilder.toString();
	}

	/**
	 * Changes unlimited length pattern to limited length pattern. It is done by
	 * replacing constructs with "*" and "+" symbols with their finite 
	 * counterparts - "{0,n}" and {1,n}. 
	 * As a side effect block quotes are replaced with normal quotes
	 * by using {@link #removeBlockQuotes(String)}.
	 * 
	 * @param pattern pattern to be finitized
	 * @param infinity "n" number
	 * @return limited length pattern
	 */
	public static String finitize(String pattern, int infinity) {
		String finitePattern = removeBlockQuotes(pattern);
		
		Matcher starMatcher = STAR_PATTERN.matcher(finitePattern);
		finitePattern = starMatcher.replaceAll("{0," + infinity + "}");
		
		Matcher plusMatcher = PLUS_PATTERN.matcher(finitePattern);
		finitePattern = plusMatcher.replaceAll("{1," + infinity + "}");
		
		Matcher rangeMatcher = RANGE_PATTERN.matcher(finitePattern);
		finitePattern = rangeMatcher.replaceAll("{$1," + infinity + "}");
		
		return finitePattern;
	}

	public static Pattern compile(SrxDocument document, String regex) {