List of usage examples for java.lang StringBuilder replace
@Override public StringBuilder replace(int start, int end, String str)
From source file:org.structr.web.maintenance.deploy.FileImportVisitor.java
private String harmonizeFileSeparators(final String... sources) { final StringBuilder buf = new StringBuilder(); for (final String src : sources) { buf.append(src);/*from ww w . ja v a 2 s . co m*/ } int pos = buf.indexOf("\\"); while (pos >= 0) { buf.replace(pos, pos + 1, "/"); pos = buf.indexOf("\\"); } return buf.toString(); }
From source file:com.marklogic.contentpump.SplitDelimitedTextReader.java
protected String convertToLine(String[] values) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < values.length; i++) { if (i == values.length - 1 && values[i].trim().equals("")) { sb.append(lineSeparator);/*from w ww . j a va2 s. co m*/ return sb.toString(); } String s = values[i]; sb.append(s); sb.append(delimiter); } sb.replace(sb.length() - 1, sb.length(), lineSeparator); return sb.toString(); }
From source file:org.kuali.rice.krad.uif.service.impl.UifDefaultingServiceImpl.java
@Override public String deriveHumanFriendlyNameFromPropertyName(String camelCasedName) { // quick check to make sure there is a property name to modify if (StringUtils.isBlank(camelCasedName)) { return camelCasedName; }/*from ww w . jav a2 s. c om*/ // We only want to include the component after the last property separator if (camelCasedName.contains(".")) { camelCasedName = StringUtils.substringAfterLast(camelCasedName, "."); } StringBuilder label = new StringBuilder(camelCasedName); // upper case the 1st letter label.replace(0, 1, label.substring(0, 1).toUpperCase()); // loop through, inserting spaces when cap for (int i = 0; i < label.length(); i++) { if (Character.isUpperCase(label.charAt(i)) || Character.isDigit(label.charAt(i))) { label.insert(i, ' '); i++; } } return label.toString().trim(); }
From source file:org.moe.natjgen.XcodeFullDocumentation.java
private void replaceAll(StringBuilder builder, String from, String to) { int idx = 0;//from ww w .j a va 2s. c o m int flen = from.length(); while ((idx = builder.indexOf(from, idx)) != -1) { builder.replace(idx, idx + flen, to); } }
From source file:com.gargoylesoftware.htmlunit.util.UrlUtils.java
/** * Encodes every occurrence of the escape character '%' in the given input * string that is not followed by two hexadecimal characters. * @param str the input string//from w w w. ja va2 s .c o m * @return the given input string where every occurrence of <code>%</code> in * invalid escape sequences has been replace by <code>%25</code> * @throws UnsupportedEncodingException should never happen */ private static String encodePercentSign(final byte[] input) throws UnsupportedEncodingException { if (input == null) { return null; } final StringBuilder result = new StringBuilder(new String(input, "US-ASCII")); int state = -0; int offset = 0; for (int i = 0; i < input.length; i++) { final byte b = input[i]; if (b == '%') { state = 1; } else if (state == 1 || state == 2) { if (('0' <= b && b <= '9') || ('A' <= b && b <= 'F') || ('a' <= b && b <= 'f')) { state++; if (state == 3) { state = 0; } } else { final int st = i - state + offset; result.replace(st, st + 1, "%25"); offset = offset + 2; state = 0; } } } if (state == 1 || state == 2) { final int st = input.length - state + offset; result.replace(st, st + 1, "%25"); } return result.toString(); }
From source file:it.andreascarpino.ansible.inventory.type.AnsibleVariable.java
public String listToString(Collection<?> list) { final StringBuilder buf = new StringBuilder(); buf.append("'["); if (!list.isEmpty()) { for (Object o : list) { if (ClassUtils.isPrimitiveOrWrapper(o.getClass()) || o instanceof String) { buf.append("'" + o + "'"); } else { buf.append(valueToString(o)); }// w w w .ja v a 2 s.com buf.append(", "); } buf.replace(buf.length() - 2, buf.length(), ""); } buf.append("]'"); return buf.toString(); }
From source file:org.codice.ddf.opensearch.endpoint.query.OpenSearchQuery.java
private void addCaretsToStringBuilder(StringBuilder stringBuilder, int endIndex, int startIndex) { for (int insertCaretIndex = startIndex + 1; insertCaretIndex <= endIndex; insertCaretIndex++) { stringBuilder.replace(insertCaretIndex, insertCaretIndex + 1, CARET); }//from w w w . jav a 2 s. com }
From source file:org.sonar.api.utils.XpathParser.java
/** * Fix the error occured when parsing a string containing unicode character * Example : &u20ac; will be replaced by € *//*from w ww. java 2 s . c om*/ protected String fixUnicodeChar(String text) { String unicode = "&u"; StringBuilder replace = new StringBuilder(text); if (text.indexOf(unicode) >= 0) { Pattern p = Pattern.compile("&u([0-9a-fA-F]{1,4});"); Matcher m = p.matcher(replace.toString()); int nbFind = 0; while (m.find()) { // Add one index each time because we add one character each time (&u -> &#x) replace.replace(m.start() + nbFind, m.end() + nbFind, "&#x" + m.group(1) + ";"); nbFind++; } } return replace.toString(); }
From source file:org.jumpmind.metl.core.runtime.component.Sorter.java
protected void appendColumns(StringBuilder sql, ModelEntity entity) { for (ModelAttribute attribute : entity.getModelAttributes()) { sql.append(attribute.getName()).append(" /* ").append(entity.getName()).append(".") .append(attribute.getName()).append(" */").append(","); }//from w w w . jav a 2 s . c o m sql.replace(sql.length() - 1, sql.length(), ""); }
From source file:com.amazonaws.services.kinesis.connectors.redshift.RedshiftManifestEmitter.java
/** * Builds a String from the members of a Set of String * /* w ww .j a v a2 s . co m*/ * @param members * List of String, each member will be surrounded by single quotes * @param prepend * beginning of String * @param delimiter * between each member * @param append * end of String * @return String in format: {prepend} * '{member1}'{delimiter}'{member2}'{delimiter}...'{lastMember}'{app e n d } */ private String getCollectionString(Collection<String> members, String prepend, String delimiter, String append) { StringBuilder s = new StringBuilder(); s.append(prepend); for (String m : members) { s.append("'"); s.append(m); s.append("'"); s.append(delimiter); } s.replace(s.length() - delimiter.length(), s.length(), ""); s.append(append); return s.toString(); }