/** * 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); }
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_", "\""));
/** * 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); }
/** * Replace special characters with entities for HTML content. * special: '&', '"', '\'', '<', '>', '\n' * * @param x string to quote * @return equivilent string using entities for any special chars */ static public String quoteHtmlContent(String x) { return replace(x, htmlIn, htmlOut); }
/** * Replaces all occurrences of "patterns" in "v" with "values" * * @param v original String * @param patterns patterns to match * @param values replacement values * @return munged String */ public static String replaceList(String v, String[] patterns, String[] values) { for (int i = 0; i < patterns.length; i++) { v = replace(v, patterns[i], values[i]); } return v; }
/** * Replace any char "out" in s with "in". * * @param s string to replace * @param out repalce this character * @param in with this string * @return modified string if needed */ static public String replace(String s, char out, String in) { if (s.indexOf(out) < 0) { return s; } // gotta do it StringBuffer sb = new StringBuffer(s); replace(sb, out, in); return sb.toString(); }
/** * Replaces all occurrences of "patterns" in "v" with "values" * * @param v original String * @param patterns patterns to match * @param values replacement values * @return munged String */ public static String replaceList(String v, List patterns, List values) { if (patterns.size() != values.size()) { throw new IllegalArgumentException( "Patterns list not the same size as values list"); } for (int i = 0; i < patterns.size(); i++) { v = replace(v, (String) patterns.get(i), (String) values.get(i)); } return v; }
/** * Construct and return a list of Strings where each string is the result * of replacing all of the patterns with the corresponding values for * each String in the given sourceList . * * @param sourceList original list of Strings * @param patterns patterns to replace * @param values replacement values * @return new list with replaced values */ public static List replaceList(List sourceList, String[] patterns, String[] values) { List result = new ArrayList(); for (int i = 0; i < sourceList.size(); i++) { String str = (String) sourceList.get(i); for (int patternIdx = 0; patternIdx < patterns.length; patternIdx++) { if (patterns[patternIdx] != null) { str = StringUtil.replace(str, patterns[patternIdx], values[patternIdx]); } } result.add(str); } return result; }
int pos = x.indexOf(replaceChar[i]); if (pos >= 0) { replace(sb, replaceChar[i], replaceWith[i]);
private CodeFlagTables(short fxy, String name) { this.fxy = fxy; this.name = (name == null) ? fxy() : StringUtil.replace(name, ' ', "_") + "("+fxy()+")"; map = new HashMap<Integer, String>(20); }
/** * Remove all text contained within "< >" tags. * * @param html The source html string. * @return The raw text. */ public static String stripTags(String html) { StringBuffer stripped = new StringBuffer(); while (html.length() > 0) { int idx = html.indexOf("<"); if (idx < 0) { stripped.append(html.trim()); break; } String text = html.substring(0, idx); text = text.trim(); if (text.length() > 0) { stripped.append(text + " \n"); } html = html.substring(idx); int idx2 = html.indexOf(">"); if (idx2 < 0) { break; } html = html.substring(idx2 + 1); } stripped = new StringBuffer(replace(stripped.toString(), " ", "")); return stripped.toString(); }
text = StringUtil.replace(text, "\n", " "); StringBuffer buff = new StringBuffer(); while (text.length() > 0) {