List of usage examples for java.lang StringBuffer deleteCharAt
@Override public synchronized StringBuffer deleteCharAt(int index)
From source file:com.aw.core.dao.AWQueryRunner.java
public static String buildSQLLog(String sql, Object[] filterKeys) { StringBuffer buf = new StringBuffer(); buf.append(sql);//from ww w . j ava 2 s . co m int idx = 0; while (buf.indexOf("?") >= 0) { int pos = buf.indexOf("?"); buf.deleteCharAt(pos); Object filterKey = filterKeys[idx]; if (filterKey instanceof String) filterKey = "'" + filterKey + "'"; buf.insert(pos, filterKey); idx++; } // if (filterKeys != null) { // buf.append(" params:"); // buf.append(Arrays.asList(filterKeys).toString()); // } return buf.toString(); }
From source file:Utils.java
/** * Add two URI path segments. Handles null and empty paths, path and query * params (eg ?a=b or ;JSESSIONID=xxx) and avoids duplicate '/' * /*from w w w . ja va 2s.c o m*/ * @param p1 * URI path segment * @param p2 * URI path segment * @return Legally combined path segments. */ public static String addPaths(String p1, String p2) { if (p1 == null || p1.length() == 0) { if (p1 != null && p2 == null) return p1; return p2; } if (p2 == null || p2.length() == 0) return p1; int split = p1.indexOf(';'); if (split < 0) split = p1.indexOf('?'); if (split == 0) return p2 + p1; if (split < 0) split = p1.length(); StringBuffer buf = new StringBuffer(p1.length() + p2.length() + 2); buf.append(p1); if (buf.charAt(split - 1) == '/') { if (p2.startsWith(SLASH)) { buf.deleteCharAt(split - 1); buf.insert(split - 1, p2); } else buf.insert(split, p2); } else { if (p2.startsWith(SLASH)) buf.insert(split, p2); else { buf.insert(split, '/'); buf.insert(split + 1, p2); } } return buf.toString(); }
From source file:org.socraticgrid.util.format.PatientIdFormatUtil.java
/** * Parse an optionally HL7 encoded patient identifier. If the patient * identifier is not HL7 encoded, the original id will be returned. * The format of an HL7 encoded patient id is * "<id>^^^&<home coummunity id>&ISO" * /*w w w. java2 s .c o m*/ * @param receivedPatientId Optionally HL7 encoded patient identifier * @return Parsed patient id */ public static String parsePatientId(String receivedPatientId) { log.debug("Parsing patient id: " + receivedPatientId); String patientId = receivedPatientId; if ((patientId != null) && (patientId.length() > 0)) { // In some cases we see a quote - in others we do not. So lets strip them off if we see them. //--------------------------------------------------------------------------------------------- if ((patientId.startsWith("'")) && (patientId.length() > 1)) { StringBuffer sbPatientId = new StringBuffer(patientId); if (patientId.endsWith("'")) { sbPatientId.deleteCharAt(sbPatientId.length() - 1); // strip off the ending quote } sbPatientId.deleteCharAt(0); // strip off hte first char quote patientId = sbPatientId.toString(); } int componentIndex = patientId.indexOf("^"); log.debug("Index: " + componentIndex); if (componentIndex != -1) { patientId = patientId.substring(0, componentIndex); log.debug("Parsed patient id: " + patientId); } } return patientId; }
From source file:com.github.DroidPHP.Utils.ConfParser.java
public static String filterValue(String mString) { StringBuffer sb = new StringBuffer(mString); if (mString.startsWith("\"") || mString.startsWith("'")) { sb.setCharAt(0, ' '); }/*from w w w .j a va 2 s . c o m*/ if (mString.endsWith("\"") || mString.endsWith("'")) { sb.deleteCharAt(mString.length() - 1); } mString = null; return sb.toString().trim(); }
From source file:Main.java
public static String removeBlanks(String content) { if (content == null) { return null; }//from w w w .j a va2 s . c om StringBuffer buff = new StringBuffer(); buff.append(content); for (int i = buff.length() - 1; i >= 0; i--) { if (' ' == buff.charAt(i) || ('\n' == buff.charAt(i)) || ('\t' == buff.charAt(i)) || ('\r' == buff.charAt(i))) { buff.deleteCharAt(i); } } return buff.toString(); }
From source file:com.orientechnologies.orient.jdbc.H2.java
private static void trim(StringBuffer section) { while (section.charAt(section.length() - 1) == SPACE_CHAR) section.deleteCharAt(section.length() - 1); }
From source file:Main.java
private static String removeSingleQuotes(StringBuffer tempBuffer, int questionSignIndex) { int delRightIndex = tempBuffer.indexOf("'", questionSignIndex); int delLeftIndex = tempBuffer.lastIndexOf("'", questionSignIndex); if (isDelSingleQuotes(tempBuffer, delLeftIndex, delRightIndex)) { tempBuffer.deleteCharAt(delRightIndex); tempBuffer.deleteCharAt(delLeftIndex); }/*from w ww. j a v a2 s.c om*/ return tempBuffer.toString(); }
From source file:Main.java
/** * Replaces successive XML space characters by a single space character (<tt>' '</tt>) * then removes leading and trailing space characters if any. * /*w w w. ja v a 2s.co m*/ * @param value string to be processed * @return processed string */ public static final String collapseWhiteSpace(CharSequence value) { StringBuffer buffer = new StringBuffer(); compressWhiteSpace(value, buffer); int last = buffer.length() - 1; if (last >= 0) { if (buffer.charAt(last) == ' ') { buffer.deleteCharAt(last); --last; } if (last >= 0 && buffer.charAt(0) == ' ') buffer.deleteCharAt(0); } return buffer.toString(); }
From source file:org.socraticgrid.util.format.PatientIdFormatUtil.java
/** * Parse an optionally HL7 encoded community id. If the patient * identifier is not HL7 encoded, null will be returned. * The format of an HL7 encoded patient id is * "<id>^^^&<home coummunity id>&ISO" * /*from ww w . ja v a 2 s.co m*/ * @param encodedPatientId Optionally HL7 encoded patient identifier * @return Parsed community id */ public static String parseCommunityId(String encodedPatientId) { log.debug("Parsing community id: " + encodedPatientId); String communityId = null; if ((encodedPatientId != null) && (encodedPatientId.length() > 0)) { String workingCommunityId = encodedPatientId; // In some cases we see a quote - in others we do not. So lets strip them off if we see them. //--------------------------------------------------------------------------------------------- if ((workingCommunityId.startsWith("'")) && (workingCommunityId.length() > 1)) { StringBuffer sbCommunityId = new StringBuffer(workingCommunityId); if (workingCommunityId.endsWith("'")) { sbCommunityId.deleteCharAt(sbCommunityId.length() - 1); // strip off the ending quote } sbCommunityId.deleteCharAt(0); // strip off hte first char quote workingCommunityId = sbCommunityId.toString(); } // First remove the first components int componentIndex = workingCommunityId.lastIndexOf("^"); log.debug("Index: " + componentIndex); if ((componentIndex != -1) && (workingCommunityId.length() > (componentIndex + 1))) { workingCommunityId = workingCommunityId.substring(componentIndex + 1); log.debug("Working community id after first components removed: " + workingCommunityId); if (workingCommunityId.startsWith("&")) { workingCommunityId = workingCommunityId.substring(1); } int subComponentIndex = workingCommunityId.indexOf("&"); if (subComponentIndex != -1) { workingCommunityId = workingCommunityId.substring(0, subComponentIndex); } communityId = workingCommunityId; } } return communityId; }
From source file:com.jnj.b2b.storefront.util.MetaSanitizerUtil.java
/** * Takes a string of words, removes duplicates and returns a comma separated list of keywords as a String * //from ww w. j av a2 s . c o m * @param keywords * Keywords to be sanitized * @return String of comma separated keywords */ public static String sanitizeKeywords(final String keywords) { final String clean = (StringUtils.isNotEmpty(keywords) ? Jsoup.parse(keywords).text() : ""); // Clean html final String[] words = StringUtils.split(clean.replace("\"", "")); // Clean quotes // Remove duplicates final StringBuffer noDupes = new StringBuffer(); for (final String word : words) { if (noDupes.indexOf(word) == -1) { noDupes.append(word).append(','); } } if (noDupes.length() > 0) { noDupes.deleteCharAt(noDupes.length() - 1); } return noDupes.toString(); }