/** * Replace special characters with entities for XML attributes. * special: '&', '<', '>', '\'', '"', '\r', '\n' * * @param x string to quote * @return equivilent string using entities for any special chars */ static public String quoteXmlAttribute(String x) { return replace(x, xmlIn, xmlOut); }
/** * Clean up strings to be used in Netcdf Object names * @param name original name * @return cleaned up name */ static public String cleanName(String name) { if (name == null) return null; int pos = name.indexOf("(see"); if (pos < 0) pos = name.indexOf("(See"); if (pos > 0) name = name.substring(0,pos); name = StringUtil2.replace(name, '/', "-"); StringBuilder sb = new StringBuilder(name); StringUtil2.replace(sb, '+', "plus"); StringUtil2.remove(sb, ".;,=[]()/*\""); return StringUtil2.collapseWhitespace(sb.toString().trim()); }
private String normalize(String units) { if (units.equals("/second")) units = "1/sec"; if (units.equals("degrees K")) units = "K"; else { units = StringUtil2.substitute(units, "**", "^"); units = StringUtil2.remove(units, ')'); units = StringUtil2.remove(units, '('); } return units; }
public static void main2(String args[]) { if (args.length < 2) { showUsage(); return; } if (args[0].equalsIgnoreCase("escape")) { String ok = (args.length > 2) ? args[2] : ""; System.out.println(" escape(" + args[1] + "," + ok + ")= " + StringUtil2.escape(args[1], ok)); } else if (args[0].equalsIgnoreCase("unescape")) { System.out.println(" unescape(" + args[1] + ")= " + StringUtil2.unescape(args[1])); } else { showUsage(); } }
private String unescapeAttributeStringValues(String value) { return StringUtil2.substitute(value, substAttributeStrings, escapeAttributeStrings); }
public CoverageCoordAxisBuilder setDependsOn(String dependsOn) { if (dependsOn != null && dependsOn.trim().length() > 0) { List<String> temp = new ArrayList<>(); Collections.addAll(temp, StringUtil2.splitString(dependsOn)); this.dependsOn = Collections.unmodifiableList(temp); } else { this.dependsOn = Collections.emptyList(); } return this; }
line = dataIS.readLine(); if (line != null) { line = StringUtil2.remove(line, '*'); String[] split = StringUtil2.splitString(line); scale = Integer.parseInt(split[0].trim()); refVal = Integer.parseInt(split[1].trim());
public static String cleanup(String s) { if (s == null) return null; return cleanup(s.getBytes(CDM.utf8Charset)); }
String snum = StringUtil2.cleanup(cols.get(0).text()).trim(); String desc = StringUtil2.cleanup(cols.get(1).text()).trim(); if (snum.contains("Reserved") || desc.contains("Reserved") || desc.contains("Missing") ) { if (debugParam) System.out.printf("*** Skip Reserved %s%n", row.text()); String snum = StringUtil2.cleanup(cols.get(0).text()).trim(); String desc = StringUtil2.cleanup(cols.get(1).text()).trim(); if (snum.contains("Reserved") || desc.contains("Reserved") || desc.contains("Missing") ) { if (debugParam) System.out.printf("*** Skip Reserved %s%n", row.text()); int lastPos = url.lastIndexOf('.'); String filename = "Table4" + url.substring(pos, lastPos); filename = StringUtil2.removeWhitespace(filename); filename = StringUtil2.substitute(filename,"-", "."); writeParamTableXml(filename, title, url, filename, stuff);
String snum = StringUtil2.cleanup(cols.get(0).text()).trim(); String desc = StringUtil2.cleanup(cols.get(1).text()).trim(); if (snum.contains("Reserved") || desc.contains("Reserved") ) { if (debug) System.out.printf("*** Skip Reserved %s%n", row.text()); String filename = StringUtil2.removeWhitespace(tableName); writeCodeTableXml(filename, title, url, tableName, stuff);
public String getPath() { return (path == null) ? null : StringUtil2.unescape(path); }
public HashMap<Integer, Grib1Parameter> parseXml(Element root) { HashMap<Integer, Grib1Parameter> result = new HashMap<>(); Element fnmocTable = root.getChild("fnmocTable"); List<Element> params = fnmocTable.getChildren("entry"); for (Element elem1 : params) { int code; try { code = Integer.parseInt(elem1.getChildText("grib1Id")); } catch (NumberFormatException e) { System.out.printf("BAD number= %s%n", elem1.getChildText("grib1Id")); continue; } String desc = elem1.getChildText("description"); if (desc == null) continue; //if (desc.startsWith("no definition")) continue; // skip; use standard def desc = StringUtil2.collapseWhitespace(desc); String units = elem1.getChildText("unitsFNMOC"); if (units == null) units = ""; String name = elem1.getChildText("name"); Grib1Parameter parameter = new Grib1Parameter(Grib1ParamTableReader.this, code, name, desc, units, null); result.put(parameter.getNumber(), parameter); if (debug) System.out.printf(" %s%n", parameter); } useName = true; return result; } }
static public String makeNameFromDescription(String desc) { if (desc == null) return null; int pos = desc.indexOf("(see"); if (pos < 0) pos = desc.indexOf("(See"); if (pos > 0) desc = desc.substring(0, pos); StringBuilder sb = new StringBuilder(desc.trim()); StringUtil2.replace(sb, '+', "plus"); StringUtil2.replace(sb, "/. ", "-p_"); StringUtil2.remove(sb, ";,=[]()"); return sb.toString(); }
public static void addAlias(String aliasKey, String actual) { alias.put(aliasKey, StringUtil2.substitute(actual, "\\", "/")); }
static String cleanNumber(String s) { return StringUtil2.remove(s, ' '); }
public void addDatasetType(String datasetTypes) { // if they list datasetType explicitly, remove defaults if (!explicit) datasets = EnumSet.noneOf(PointDatasetType.class); explicit = true; String[] types = StringUtil2.splitString(datasetTypes); for (String type : types) { try { PointDatasetType fdt = PointDatasetType.valueOf(type); datasets.add(fdt); } catch (Exception e) { log.warn("Dont recognize PointDatasetType " + type); } } }