List of usage examples for java.lang StringBuffer charAt
@Override public synchronized char charAt(int index)
From source file:org.jfaster.mango.support.Randoms.java
public static String randomString(int maxLength) { int length = randomInt(maxLength) + 1; StringBuffer buffer = new StringBuffer("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); StringBuffer sb = new StringBuffer(); int range = buffer.length(); for (int i = 0; i < length; i++) { sb.append(buffer.charAt(randomInt(range))); }/*from www . j a va2s . co m*/ return sb.toString(); }
From source file:com.yunmel.syncretic.utils.commons.StrUtils.java
/** * ?// w ww . j a v a2 s. c o m * @param str * @return */ public static String firstCharToUpper(String str) { StringBuffer sb = new StringBuffer(str); sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); return sb.toString(); }
From source file:com.yunmel.syncretic.utils.commons.StrUtils.java
/** * ??//from w w w . ja v a 2 s .c om * @param str * @return */ public static String firstCharToLower(String str) { StringBuffer sb = new StringBuffer(str); sb.setCharAt(0, Character.toLowerCase(sb.charAt(0))); return sb.toString(); }
From source file:Main.java
private static String saveNonAsciiAsNumberEntity(String p_src) { if (p_src == null || p_src.length() == 0 || p_src.trim().length() == 0) { return p_src; }/*from w w w . j a v a 2 s . c o m*/ int length = p_src.length(); StringBuffer src = new StringBuffer(p_src); StringBuffer ret = new StringBuffer(length); for (int i = 0; i < length; i++) { char c = src.charAt(i); int ci = (int) c; if (isAscii(ci)) { ret.append(c); } else if (isEncodeable(src, i)) { ret.append(NUMBER_ENTITY_START).append(ci).append(NUMBER_ENTITY_END); } else { ret.append(c); } } return ret.toString(); }
From source file:com.redhat.rhn.common.util.ServletUtils.java
private static boolean endsWith(StringBuffer buffer, char c) { if (buffer.length() == 0) { return false; }/*from w w w. j a v a 2s.c om*/ return buffer.charAt(buffer.length() - 1) == c; }
From source file:Main.java
/** * Escapes characters that are not allowed in various places * in XML by replacing all invalid characters with * <code>getEscape(c)</code>. * //from ww w .j a v a2 s . c om * @param buffer The <code>StringBuffer</code> containing * the text to escape in place. */ public static void XMLEscape(StringBuffer buffer) { if (buffer == null) { return; } char c; String escape; for (int i = 0; i < buffer.length();) { c = buffer.charAt(i); escape = getEscape(c); if (escape == null) { i++; } else { buffer.replace(i, i + 1, escape); i += escape.length(); } } }
From source file:com.griddynamics.jagger.diagnostics.visualization.GraphVisualizationHelper.java
private static String formatLabel(String string, int maxLength) { StringBuffer buffer = new StringBuffer(string); int runLength = 0; for (int i = 0; i < buffer.length(); i++) { if (buffer.charAt(i) != '\n') { runLength++;//from w ww .jav a2 s . co m } else { runLength = 0; } if (runLength >= maxLength) { buffer.insert(i, '\n'); runLength = 0; } } return buffer.toString().replaceAll("\\n", "<br/>"); }
From source file:com.bstek.dorado.util.PathUtils.java
public static String concatPath(String... paths) { StringBuffer result = new StringBuffer(); for (String path : paths) { if (StringUtils.isEmpty(path)) { continue; }/*w ww. j av a2 s . c o m*/ if (result.length() > 0) { boolean endsWithDelim = (result.charAt(result.length() - 1) == PATH_DELIM); boolean startsWithDelim = (path.charAt(0) == PATH_DELIM); if (endsWithDelim) { if (startsWithDelim) { result.setLength(result.length() - 1); } } else if (!startsWithDelim) result.append(PATH_DELIM); } result.append(path); } return result.toString(); }
From source file:HashUtil.java
/** * This is buzhash the hash function on which most other Hash methods are * built./*from w ww . ja va 2 s. co m*/ */ private static long buzhash(StringBuffer arg) { /* Hash StringBuffer */ long h = initial_hash; for (int i = 0; i < arg.length(); ++i) h = (h << 1) ^ (h >>> 63) ^ mix_master[(arg.charAt(i) ^ (arg.charAt(i) >>> 8)) & 0xff]; return h; }
From source file:TextUtilities.java
/** * Trims the specified string on the right only. *//*from w ww.j a va 2 s . c o m*/ public static String trimRight(String s) { StringBuffer buf = new StringBuffer(s); int length = buf.length(); while (Character.isWhitespace(buf.charAt(length - 1))) buf.setLength(--length); return buf.toString(); }