/*
********************************************************************************
- * Copyright (C) 2009-2010, Google, International Business Machines Corporation *
+ * Copyright (C) 2009-2011, Google, International Business Machines Corporation *
* and others. All Rights Reserved. *
********************************************************************************
*/
import java.text.ParsePosition;
import java.util.Arrays;
import java.util.Comparator;
-import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
import com.ibm.icu.text.StringTransform;
+import com.ibm.icu.text.SymbolTable;
import com.ibm.icu.text.UnicodeSet;
import com.ibm.icu.util.Freezable;
// Note: we don't currently have any state, but intend to in the future,
// particularly for the regex style supported.
+ private SymbolTable symbolTable;
+
+ /**
+ * Set the symbol table for internal processing
+ * @internal
+ */
+ public SymbolTable getSymbolTable() {
+ return symbolTable;
+ }
+
+ /**
+ * Get the symbol table for internal processing
+ * @internal
+ */
+ public UnicodeRegex setSymbolTable(SymbolTable symbolTable) {
+ this.symbolTable = symbolTable;
+ return this;
+ }
+
/**
* Adds full Unicode property support, with the latest version of Unicode,
* to Java Regex, bringing it up to Level 1 (see
// brute force replacement; do twice to allow for different order
// later on can optimize
for (int i = 0; i < 2; ++i) {
- for (Iterator<String> it = variables.keySet().iterator(); it.hasNext();) {
- String variable = it.next();
- String definition = variables.get(variable);
- for (Iterator<String> it2 = variables.keySet().iterator(); it2.hasNext();) {
- String variable2 = it2.next();
- if (variable.equals(variable2)) continue;
- String definition2 = variables.get(variable2);
+ for (Entry<String, String> entry : variables.entrySet()) {
+ String variable = entry.getKey(),
+ definition = entry.getValue();
+
+ for (Entry<String, String> entry2 : variables.entrySet()) {
+ String variable2 = entry2.getKey(),
+ definition2 = entry2.getValue();
+ if (variable.equals(variable2)) {
+ continue;
+ }
String altered2 = definition2.replace(variable, definition);
if (!altered2.equals(definition2)) {
unused.remove(variable);
private int processSet(String regex, int i, StringBuilder result, UnicodeSet temp, ParsePosition pos) {
try {
pos.setIndex(i);
- UnicodeSet x = temp.clear().applyPattern(regex, pos, null, 0);
+ UnicodeSet x = temp.clear().applyPattern(regex, pos, symbolTable, 0);
x.complement().complement(); // hack to fix toPattern
result.append(x.toPattern(false));
i = pos.getIndex() - 1; // allow for the loop increment
String variable = null;
StringBuffer definition = new StringBuffer();
int count = 0;
- for (Iterator<String> it = lines.iterator(); it.hasNext();) {
- String line = it.next();
+ for (String line : lines) {
++count;
// remove initial bom, comments
if (line.length() == 0) continue;