/** * 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 quoteXmlContent(String x) { return replace(x, xmlInC, xmlOutC); }
public static void main(String args[]) { String s = " "; System.out.printf("escape(%s) == %s%n", s, escape(s, "")); }
/** * Merge the given strings, using the given delimiter between each. * * @param delimiter The delimiter. * @param args A List of objects whose toString value are merged. * @return The given object.toString values concatenated together with the delimiter between each. */ public static String join(String delimiter, List args) { return join(delimiter, listToStringArray(args)); }
/** * test * * @param args args */ public static void main3(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 + ")= " + escape(args[1], ok)); } else if (args[0].equalsIgnoreCase("unescape")) { System.out.println(" unescape(" + args[1] + ")= " + unescape(args[1])); } else { showUsage(); } }
coords = StringUtil.replace(coords, "\n", " "); while (true) { String newCoords = StringUtil.replace(coords, " ,", ","); if (newCoords.equals(coords)) { break; String newCoords = StringUtil.replace(coords, ", ", ","); if (newCoords.equals(coords)) { break; List tokens = StringUtil.split(coords, " ", true, true); double[][] result = null; for (int pointIdx = 0; pointIdx < tokens.size(); pointIdx++) { String tok = (String) tokens.get(pointIdx); List numbers = StringUtil.split(tok, ","); if ((numbers.size() != 2) && (numbers.size() != 3)) {
s = replaceList(s, new String[]{"\"\"\",", ",\"\"\"", "\"\""}, new String[]{"_QUOTE_\",", ",\"_QUOTE_", "_QUOTE_"}); state = INQUOTE; } else if (c == ',') { line.add(replace(word, "_QUOTE_", "\"")); word = ""; } else if (c == '\n') { line.add(replace(word, "_QUOTE_", "\"")); word = ""; if (!skipFirst || (lines.size() > 1)) { line.add(replace(word, "_QUOTE_", "\"")); word = ""; state = LOOKING; line.add(replace(word, "_QUOTE_", "\""));
staxWriter.writeAttribute("name", StringUtil.quoteXmlAttribute(name)); staxWriter.writeAttribute("units", StringUtil.quoteXmlAttribute(v.getUnitsString())); staxWriter.writeAttribute("bufr", StringUtil.quoteXmlAttribute(desc)); // */ String s = StringUtil.filter7bits(mdata.next().toString()); staxWriter.writeCharacters(StringUtil.quoteXmlContent(s));
long y = convert(str(matcher.group(gidx++), "0")); gidx++; long m = convert(str(matcher.group(gidx++), "0")); gidx++; long d = convert(str(matcher.group(gidx++), "0")); gidx++; gidx++; long h = convert(str(matcher.group(gidx++), "0")); gidx++; long min = convert(str(matcher.group(gidx++), "0")); gidx++; long sec = convert(str(matcher.group(gidx++), "0"));
int classId = Integer.parseInt(flds[fldidx++].trim()); int xy = Integer.parseInt(flds[fldidx++].trim()); String name = StringUtil.remove(flds[fldidx++], '"'); String units = StringUtil.filter(flds[fldidx++], " %+-_/()*"); // alphanumeric plus these chars int scale = Integer.parseInt(clean(flds[fldidx++].trim())); int refVal = Integer.parseInt(clean(flds[fldidx++].trim()));
} else if (patternString.startsWith("glob:")) { patternString = patternString.substring("glob:".length()); patternString = wildcardToRegexp(patternString); if (!StringUtil.containsRegExp(patternString)) { return false;
/** * A utility method to do multiple appends to a StringBuffer. * If the given object is null the string "null" will be appended. If * non-null then we append to the StringBuffer the results of * sn.toString (); * * @param sb StringBuffer to append to (may be <code>null</code>) * @param s1 first object to append * @param s2 second object to append * @return StringBuffer with appended objects */ public static StringBuffer append(StringBuffer sb, Object s1, Object s2) { sb = append(sb, s1); sb.append((s2 == null) ? "null" : s2.toString()); return sb; }
/** * Pad the given string with spaces on the left up to the given length. * * @param s String to pad * @param desiredLength ending length * @return padded String */ public static String padLeft(String s, int desiredLength) { return padLeft(s, desiredLength, " "); }
/** * Merge the given strings, using the given delimiter between each. * * @param delimiter The delimiter. * @param args An array of Strings to merge. * @return The given strings concatenated together with the delimiter between each. */ public static String join(String delimiter, Object[] args) { return join(delimiter, args, false); }
/** * A utility method to do multiple appends to a StringBuffer. * If the given object is null the string "null" will be appended. If * non-null then we append to the StringBuffer the results of * sn.toString (); * * @param sb StringBuffer to append to (may be <code>null</code>) * @param s1 first object to append * @param s2 second object to append * @param s3 third object to append * @return StringBuffer with appended objects */ public static StringBuffer append(StringBuffer sb, Object s1, Object s2, Object s3) { sb = append(sb, s1, s2); sb.append((s3 == null) ? "null" : s3.toString()); return sb; }
/** * Left pad the given value with zeros up to the number of digits * * @param value The value. * @param numDigits number of digits * @return The String represenation of the value, padded with * leading "0"-s if value < 10E(numDigits-1) */ public static String padZero(int value, int numDigits) { return padLeft(String.valueOf(value), numDigits, "0"); }
/** * Merge the given strings, using a space between each. * * @param args An array of Strings to merge. * @return The given strings concatenated together with a * space between each. */ public static String join(String[] args) { return join(" ", args); }
/** * 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); }
/** * Merge the given strings, using the given delimiter between each. * * @param delimiter The delimiter. * @param args A List of objects whose toString value are merged. * @param ignoreEmptyStrings Should ignore empty strings * @return The given object.toString values concatenated together with the delimiter between each. */ public static String join(String delimiter, List args, boolean ignoreEmptyStrings) { return join(delimiter, listToStringArray(args), ignoreEmptyStrings); }
/** * A utility method to do multiple appends to a StringBuffer. * If the given object is null the string "null" will be appended. If * non-null then we append to the StringBuffer the results of * sn.toString (); * * @param sb StringBuffer to append to (may be <code>null</code>) * @param s1 first object to append * @param s2 second object to append * @param s3 third object to append * @param s4 fourth object to append * @return StringBuffer with appended objects */ public static StringBuffer append(StringBuffer sb, Object s1, Object s2, Object s3, Object s4) { sb = append(sb, s1, s2, s3); sb.append((s4 == null) ? "null" : s4.toString()); return sb; }
return baseDate; } else { wmoDate = StringUtil.padLeft(wmoDate, 6, "0");