📄 textutils.java
字号:
private static List<String> getResourcesFromJarFile(File file, String resName) { List<String> retval = new ArrayList<String>(); try { ZipFile zf = new ZipFile(file); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry)e.nextElement(); String entry = ze.getName(); if (entry.startsWith(resName)) { retval.add(entry.substring(resName.length()+1)); } } zf.close(); } catch (IOException e) {} return retval; } private static List<String> getResourcesFromDirectory(File directory) { List<String> retval = new ArrayList<String>(); File[] fileList = directory.listFiles(); for (File file : fileList) { if (file.isDirectory()) { retval.addAll(getResourcesFromDirectory(file)); } else { String fileName = file.getName(); retval.add(fileName); } } return retval; } /****************************** FOR SORTING OBJECTS ******************************/ /** * A comparator object for sorting Strings that may have numbers in them. * Created once because it is used often. */ public static final Comparator<String> STRING_NUMBER_ORDER = new Comparator<String>() { /** * Method to compare two names and give a sort order. * The comparison considers numbers in numeric order so that the * string "in10" comes after the string "in9". * * Formal definition of order. * Lets insert in string's character sequence number at start of digit sequences. * Consider that numbers in the sequence are less than chars. * * Examples below are in increasing order: * "" { } * "0" { 0, '0' } * "9" { 9, '9' } * "10" { 10, '1', '0' } * "2147483648" { 2147483648, '2', '1', '4', '7', '4', '8', '3', '6', '4', '8' } * " " { ' ' } * "-" { '-' } * "-1" { '-', 1, '1' } * "-2" { '-', 2, '2' } * "a" { 'a' } * "a0" { 'a', 0, '0' } * "a0-0" { 'a', 0, '0', '-', 0, '0' } * "a00" { 'a', 0, '0', '0' } * "a0a" { 'a', 0, '0', 'a' } * "a01" { 'a', 1, '0', '1' } * "a1" { 'a', 1, '1' } * "a[1]" { 'a', '[', 1, '1', ']' } * "a[10]" { 'a', '[', 10, '1', '0', ']' } * "in" { 'i', 'n' } * "in1" { 'i', 'n', 1, '1' } * "in1a" { 'i', 'n', 1, '1', 'a' } * "in9" { 'i', 'n', 9, '9' } * "in10" { 'i', 'n', 10, '1', '0' } * "in!" { 'i', 'n', '!' } * "ina" { 'i , 'n', 'a' } * * @param o1 the first string. * @param o2 the second string. * @return 0 if they are equal, nonzero according to order. */ public int compare(String name1, String name2) { int len1 = name1.length(); int len2 = name2.length(); int extent = Math.min(len1, len2); for(int pos = 0; pos < extent; pos++) { char ch1 = name1.charAt(pos); char ch2 = name2.charAt(pos); if (ch1 != ch2) { int digit1 = digit(ch1); int digit2 = digit(ch2); if (digit1 >= 0 || digit2 >= 0) { int pos1 = pos + 1, pos2 = pos + 1; // Positions in string to compare // One char is digit, another is not. Is previous digit ? int digit = pos > 0 ? digit(name1.charAt(--pos)) : -1; if (digit < 0 && (digit1 < 0 || digit2 < 0)) { // Previos is not digit. Number is less than non-number. return digit2 - digit1; } // Are previus digits all zeros ? while (digit == 0) digit = pos > 0 ? digit(name1.charAt(--pos)) : -1; if (digit < 0) { // All previos digits are zeros. Skip zeros further. while (digit1 == 0) digit1 = pos1 < len1 ? digit(name1.charAt(pos1++)) : -1; while (digit2 == 0) digit2 = pos2 < len2 ? digit(name2.charAt(pos2++)) : -1; } // skip matching digits while (digit1 == digit2 && digit1 >= 0) { digit1 = pos1 < len1 ? digit(name1.charAt(pos1++)) : -1; digit2 = pos2 < len2 ? digit(name2.charAt(pos2++)) : -1; } boolean dig1 = digit1 >= 0; boolean dig2 = digit2 >= 0; for (int i = 0; dig1 && dig2; i++) { dig1 = pos1 + i < len1 && digit(name1.charAt(pos1 + i)) >= 0; dig2 = pos2 + i < len2 && digit(name2.charAt(pos2 + i)) >= 0; } if (dig1 != dig2) return dig1 ? 1 : -1; if (digit1 != digit2) return digit1 - digit2; } return ch1 - ch2; } } return len1 - len2; } }; private static int digit(char ch) { if (ch < '\u0080') return ch >= '0' && ch <= '9' ? ch - '0' : -1; return Character.digit((int)ch, 10); }// /**// * Test of STRING_NUMBER_ORDER.// */// private static String[] numericStrings = {// "", // { }// "0", // { 0, '0' }// "0-0", // { 0, '0', '-', 0, '0' }// "00", // { 0, '0', '0' }// "0a", // { 0, '0', 'a' }// "01", // { 1, '0', '1' }// "1", // { 1, '1' }// "9", // { 9, '9' }// "10", // { 10, '1', '0' }// "12", // { 12, '1', '2' }// "102", // { 102, '1', '0', '2' }// "2147483648", // { 2147483648, '2', '1', '4', '7', '4', '8', '3', '6', '4', '8' }// " ", // { ' ' }// "-", // { '-' }// "-1", // { '-', 1, '1' }// "-2", // { '-', 2, '2' }// "a", // { 'a' }// "a0", // { 'a', 0, '0' }// "a0-0", // { 'a', 0, '0', '-', 0, '0' }// "a00", // { 'a', 0, '0', '0' }// "a0a", // { 'a', 0, '0', 'a' }// "a01", // { 'a', 1, '0', '1' }// "a1", // { 'a', 1, '1' }// "a[1]", // { 'a', '[', 1, '1', ']' }// "a[10]", // { 'a', '[', 10, '1', '0', ']' }// "in", // { 'i', 'n' }// "in1", // { 'i', 'n', 1, '1' }// "in1a", // { 'i', 'n', 1, '1', 'a' }// "in9", // { 'i', 'n', 9, '9' }// "in10", // { 'i', 'n', 10, '1', '0' }// "in!", // { 'i', 'n', '!' }// "ina" // { 'i , 'n', 'a' }// };//// static {// for (int i = 0; i < numericStrings.length; i++)// {// for (int j = 0; j < numericStrings.length; j++)// {// String s1 = numericStrings[i];// String s2 = numericStrings[j];// int cmp = STRING_NUMBER_ORDER.compare(s1, s2);// if (i == j && cmp != 0 || i < j && cmp >= 0 || i > j && cmp <= 0)// System.out.println("Error in TextUtils.nameSameNumeric(\"" +// s1 + "\", \"" + s2 + "\") = " + cmp);// }// }// } /** * Comparator class for sorting Objects by their string name. */ public static class ObjectsByToString implements Comparator<Object> { /** * Method to sort Objects by their string name. */ public int compare(Object o1, Object o2) { String s1 = o1.toString(); String s2 = o2.toString(); return s1.compareToIgnoreCase(s2); } } /** * Comparator class for sorting Cells by their view order. */ public static class CellsByView implements Comparator<Cell> { /** * Method to sort Cells by their view order. */ public int compare(Cell c1, Cell c2) { View v1 = c1.getView(); View v2 = c2.getView(); return v1.getOrder() - v2.getOrder(); } } /** * Comparator class for sorting Cells by their version number. */ public static class CellsByVersion implements Comparator<Cell> { /** * Method to sort Cells by their version number. */ public int compare(Cell c1, Cell c2) { return c2.getVersion() - c1.getVersion(); } } /** * Comparator class for sorting Cells by their name (NOT considering numbers in the names). */ public static class CellsByName implements Comparator<Cell> { /** * Method to sort Cells by their name. */ public int compare(Cell c1, Cell c2) { String r1 = c1.getName(); String r2 = c2.getName(); return r1.compareTo(r2); } } /** * Comparator class for sorting Cells by their date. */ public static class CellsByDate implements Comparator<Cell> { /** * Method to sort Cells by their date. */ public int compare(Cell c1, Cell c2) { Date r1 = c1.getRevisionDate(); Date r2 = c2.getRevisionDate(); return r1.compareTo(r2); } } /** * Comparator class for sorting Preferences by their name. */ public static class PrefsByName implements Comparator<Pref> { /** * Method to sort Preferences by their name. */ public int compare(Pref p1, Pref p2) { String s1 = p1.getPrefName(); String s2 = p2.getPrefName(); return s1.compareToIgnoreCase(s2); } } /** * Comparator class for sorting Networks by their name. */ public static class NetworksByName implements Comparator<Network> { /** * Method to sort Networks by their name. */ public int compare(Network n1, Network n2) { String s1 = n1.describe(false); String s2 = n2.describe(false); return s1.compareToIgnoreCase(s2); } } public static final Comparator<Connection> CONNECTIONS_ORDER = new Comparator<Connection>() { public int compare(Connection c1, Connection c2) { int i1 = c1.getPortInst().getPortProto().getPortIndex(); int i2 = c2.getPortInst().getPortProto().getPortIndex(); int cmp = i1 - i2; if (cmp != 0) return cmp; cmp = c1.getArc().getArcId() - c2.getArc().getArcId(); if (cmp != 0) return cmp; return c1.getEndIndex() - c2.getEndIndex(); } }; /** * Method to replace all special characters in the instance name coming from external files such as"/".. * @param n * @param onlyBrackets * @param correctBrackets * @return String where characters "/", "[", "]" are replacedby "_". "\" is removed. */ public static String correctName(String n, boolean onlyBrackets, boolean correctBrackets) { int index; // removing brackets only if ] is not the last item in the string // It doesn't correct brackets if {a[1],b[2],c[3]} in VerilogReading if (correctBrackets) { index = n.indexOf("]"); if (index != -1 && index < n.length()-1) { n = n.replace('[', '-'); n = n.replace("]", "-"); } } if (onlyBrackets) return n; // First replace "/" for "-" index = n.indexOf("/"); if (index != -1) n = n.replaceAll("/", "_"); // Remove possible space character representing as \ index = n.indexOf("\\"); if (index != -1) { assert(false); // detect this before n = n.substring(index+1); } return n; } /** * Class to define the kind of text string to search */ public enum WhatToSearch { ARC_NAME("Arc Name"), ARC_VAR("Arc Variable"), NODE_NAME("Node Name"), NODE_VAR("Node Variable"), EXPORT_NAME("Export Name"), EXPORT_VAR("Export Variable"), CELL_VAR("Cell Name"), TEMP_NAMES(null); private String descriptionOfObjectFound; private WhatToSearch(String descriptionOfObjectFound) { this.descriptionOfObjectFound = descriptionOfObjectFound; } public String toString() {return descriptionOfObjectFound;} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -