List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:gov.nih.nci.cabig.ctms.lang.StringTools.java
/** * Normalizes the whitespace in the given buffer in-place. * This means that the whitespace is stripped from the head and the tail * and any contiguous stretches of whitespace are converted into a single * space.//from w w w . j a v a 2 s .c o m * * @param toNormalize * @return the passed-in buffer */ public static StringBuffer normalizeWhitespace(StringBuffer toNormalize) { if (toNormalize == null) return null; // start with this value == true to completely remove leading whitespace boolean prevIsWhitespace = true; for (int i = 0; i < toNormalize.length(); i++) { if (Character.isWhitespace(toNormalize.charAt(i))) { if (prevIsWhitespace) { toNormalize.deleteCharAt(i); i--; } else { toNormalize.setCharAt(i, ' '); prevIsWhitespace = true; } } else { prevIsWhitespace = false; } } // remove (at most) one trailing ' ' if (toNormalize.length() > 0 && toNormalize.charAt(toNormalize.length() - 1) == ' ') toNormalize.deleteCharAt(toNormalize.length() - 1); return toNormalize; }
From source file:ch.entwine.weblounge.common.url.UrlUtils.java
/** * Returns <code>null</code> if the url is valid, that is, if it contains only * allowed characters. otherwise, the invalid character is returned. * //from w w w. j av a 2 s . c om * @return <code>null</code> or the invalid character */ private static Character checkUrl(String url) { StringBuffer original = new StringBuffer(url); for (int i = 0; i < original.length(); i++) { int value = original.charAt(i); // a-z if (value >= 'a' && value <= 'z') { continue; } // A-Z if (value >= 'A' && value <= 'Z') { continue; } // 0-9 if (value >= '0' && value <= '9') { continue; } // Special characters if (value == '-' || value == '_' || value == '.' || value == ',' || value == ';') { continue; } return original.charAt(i); } return null; }
From source file:org.overlord.rtgov.tests.platforms.jbossas.activityserver.JBossASActivityServerServiceTest.java
protected static void initAuth(HttpURLConnection connection) { String userPassword = "admin:admin"; String encoding = org.apache.commons.codec.binary.Base64.encodeBase64String(userPassword.getBytes()); StringBuffer buf = new StringBuffer(encoding); for (int i = 0; i < buf.length(); i++) { if (Character.isWhitespace(buf.charAt(i))) { buf.deleteCharAt(i);/*from w w w . j a v a 2 s. c o m*/ i--; } } connection.setRequestProperty("Authorization", "Basic " + buf.toString()); }
From source file:Main.java
public static StringBuffer manualRTL(StringBuffer text, boolean forWebView) { if (forWebView) { if (patternBreakingWebView.matcher(text).find()) { // handle BiDi manually // global direction is LTR because of HTML markup StringBuffer ltr = new StringBuffer(""), rtl = new StringBuffer(""); int i = 0; while (i < text.length()) { char c = text.charAt(i); if (isStrongLeftToRight(c) || !isStrongRightToLeft(c)) { while (i < text.length() && !isStrongRightToLeft(text.charAt(i))) { ltr.append(text.charAt(i)); i++;// www. ja v a 2 s .c o m } if (i == text.length()) { break; } } if (isStrongRightToLeft(text.charAt(i))) { while (i < text.length() && !isStrongLeftToRight(text.charAt(i))) { // additional end condition: start of an HTML tag if (text.charAt(i) == '<') { break; } rtl.append(text.charAt(i)); i++; } // reverse only words that Android will not display correctly by itself if (patternBreakingWebView.matcher(rtl).find()) { ltr.append(rtl.reverse()); } else { ltr.append(rtl); } rtl = new StringBuffer(""); } } return ltr; } } return text; }
From source file:Main.java
/** * Gets the column letter corresponding to the 0-based column number * //from ww w. j a v a2 s . co m * @param column the column number * @param buf the string buffer in which to write the column letter */ public static void getColumnReference(int column, StringBuffer buf) { int v = column / 26; int r = column % 26; StringBuffer tmp = new StringBuffer(); while (v != 0) { char col = (char) ('A' + r); tmp.append(col); r = v % 26 - 1; // subtract one because only rows >26 preceded by A v = v / 26; } char col = (char) ('A' + r); tmp.append(col); // Insert into the proper string buffer in reverse order for (int i = tmp.length() - 1; i >= 0; i--) { buf.append(tmp.charAt(i)); } }
From source file:org.pmedv.core.util.StringUtil.java
/** * <p>// w w w. j a v a 2 s . co m * Converts a straight text to a text with line breaks depending * on the length of a line. * </p> * <p> * If the character at <b>lineWidth</b> is not a whitespace, * the function steps back inside the character array until a * whitespace is found. * </p> * <p> * If the param html is set to true, the output string is embedded between * <html></html> tags and the line breaks are printed as <br> * instead of \n. This is for example useful for tooltip and html panel display * of the text. * <p> * * @param originalText the text to insert line breaks into * @param lineWidth the maximum length of the line (the expected position of the linebreak) * @param html force html output * * @return the converted String containing line breaks */ public static String insertLineBreaks(String originalText, int lineWidth, boolean html) { if (originalText == null) return ""; if (originalText.length() <= lineWidth) return originalText; StringBuffer text = new StringBuffer(originalText); if (html) { text.insert(0, Tags.HTML_OPEN); } for (int i = 1; i < text.length(); i++) { if (i % lineWidth == 0) { int j = i; while (text.charAt(j--) != ' ' && j > 1) ; // TODO : Remove hard coded line break and do some platform checking if (html) text.insert(j + 1, Tags.NEWLINE); else text.setCharAt(j + 1, '\n'); } } if (html) { text.append(Tags.HTML_CLOSE); } return text.toString(); }
From source file:org.squale.squalecommon.util.mapping.Mapping.java
/** * Obtention du getter d'une mtrique La mthode est recherche dans la classe correspondante, la mthode est du * type getXxxx//from w w w . j a v a2 s. c om * * @param pMetric mtrique (par exemple mccabe.class.dit) * @return mthode d'accs cette mtrique (par exemple McCabeQAClassMetricsBO.getDit) * @throws IllegalArgumentException si pMetric mal form */ public static Method getMetricGetter(String pMetric) throws IllegalArgumentException { Method result = null; int index = pMetric.lastIndexOf('.'); if (index < 0) { throw new IllegalArgumentException("Metric name should be named tool.component.name"); } String measure = pMetric.substring(0, index); String metric = pMetric.substring(index + 1); // Obtention de la classe Class cl = getMeasureClass(measure); // Un log d'erreur aura t fait par la mthode // auparavant, inutile d'engorger le log if (cl != null) { try { // On forme le nom du getter StringBuffer methodName = new StringBuffer(metric); // Respect de la norme javabean pour le caractre en majuscules methodName.setCharAt(0, Character.toTitleCase(methodName.charAt(0))); methodName.insert(0, "get"); result = cl.getMethod(methodName.toString(), null); } catch (SecurityException e) { LOG.error("Getter not found " + pMetric, e); } catch (NoSuchMethodException e) { LOG.error("Getter not found " + pMetric, e); } } return result; }
From source file:org.apache.axis.attachments.MimeUtils.java
/** * This routine will get the content type from a mulit-part mime message. * * @param mp the MimeMultipart//w w w . ja v a2s . co m * @return the content type */ public static String getContentType(javax.mail.internet.MimeMultipart mp) { StringBuffer contentType = new StringBuffer(mp.getContentType()); // TODO (dims): Commons HttpClient croaks if we don't do this. // Need to get Commons HttpClient fixed. for (int i = 0; i < contentType.length();) { char ch = contentType.charAt(i); if (ch == '\r' || ch == '\n') contentType.deleteCharAt(i); else i++; } return contentType.toString(); }
From source file:org.kuali.ext.mm.utility.BeanDDCreator.java
public static String camelCaseToString(String className) { StringBuffer newName = new StringBuffer(className); // upper case the 1st letter newName.replace(0, 1, newName.substring(0, 1).toUpperCase()); // loop through, inserting spaces when cap for (int i = 0; i < newName.length(); i++) { if (Character.isUpperCase(newName.charAt(i))) { newName.insert(i, ' '); i++;/*from w ww . ja va 2 s . c o m*/ } } return newName.toString().trim().replace("Uc", "UC"); }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Append the URL encoded OpenID message parameters to the query string of the provided URI. * // w ww .j av a 2 s . co m * @param uri URI to append OpenID message parameter to * @param message URL encoded OpenID message parameters * @return URI with message parameters appended */ public static URI appendMessageParameters(URI uri, String message) { if (uri == null || message == null) { return uri; } // build new query string StringBuffer queryBuffer = new StringBuffer(); if (uri.getRawQuery() != null) { queryBuffer.append(uri.getRawQuery()); } if (queryBuffer.length() > 0 && queryBuffer.charAt(queryBuffer.length() - 1) != '&') { queryBuffer.append('&'); } queryBuffer.append(message); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryBuffer.toString(), uri.getFragment()); } catch (URISyntaxException e) { log.error("Unable to append message parameters to URI: {}", e); } return null; }