1 package org.unicode.cldr.util; 2 3 import java.io.BufferedReader; 4 import java.io.IOException; 5 import java.util.ArrayList; 6 import java.util.List; 7 8 import org.unicode.cldr.draft.FileUtilities; 9 10 public class SpreadSheet { 11 static boolean DEBUG = CldrUtility.getProperty("SpreadSheetDebug", false); 12 convert(String filename)13 public static List<List<String>> convert(String filename) throws IOException { 14 return convert(FileUtilities.openUTF8Reader("", filename)); 15 } 16 convert(BufferedReader r)17 public static List<List<String>> convert(BufferedReader r) throws IOException { 18 List<List<String>> result = new ArrayList<List<String>>(); 19 // boolean inQuote = false; 20 while (true) { 21 String line = r.readLine(); 22 if (line == null) break; 23 if (DEBUG) { 24 System.out.println("Spreadsheet:\t" + line); 25 } 26 String[] parts = line.split("\t"); 27 List<String> row = new ArrayList<String>(parts.length); 28 for (String part : parts) { 29 if (part.startsWith("\"") && part.endsWith("\"")) { 30 row.add(part.substring(1, part.length() - 1)); 31 } else { 32 row.add(part); 33 } 34 } 35 result.add(row); 36 } 37 return result; 38 } 39 40 // for (int i = 0; i < line.length(); ++i) { 41 // char ch = line.charAt(i); // don't worry about supplementaries 42 // if (inQuote) { 43 // if (ch == '"') { 44 // inQuote = false; 45 // } 46 // } else { 47 // if (ch == ',' || ch == "\t") { 48 // 49 // } 50 // } 51 // 52 // } 53 54 }