List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:org.cryptomator.ui.model.Vault.java
/** * Tries to form a similar string using the regular latin alphabet. * /*from w w w. j ava 2 s. co m*/ * @param string * @return a string composed of a-z, A-Z, 0-9, and _. */ public static String normalize(String string) { String normalized = Normalizer.normalize(string, Form.NFD); StringBuilder builder = new StringBuilder(); for (int i = 0; i < normalized.length(); i++) { char c = normalized.charAt(i); if (Character.isWhitespace(c)) { if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') { builder.append('_'); } } else if (c < 127 && Character.isLetterOrDigit(c)) { builder.append(c); } else if (c < 127) { if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') { builder.append('_'); } } } return builder.toString(); }
From source file:hu.javaforum.commons.ReflectionHelper.java
/** * Returns the getter method of the field. It is recursive method. * * @param instanceClass The bean class//from w w w . jav a2 s .c om * @param instance The bean instance * @param fieldName The field name * @return The getter method, if it is exists * null, if the getter method is not exists */ protected static Method getGetterMethod(final Class instanceClass, final Object instance, final String fieldName) { if ("java.lang.Object".equals(instanceClass.getName())) { return null; } try { StringBuilder sb = new StringBuilder(fieldName.length() + GET_WORD.length()); sb.append(GET_WORD); sb.append(fieldName); sb.setCharAt(GET_WORD.length(), Character.toUpperCase(sb.charAt(GET_WORD.length()))); return instanceClass.getDeclaredMethod(sb.toString()); } catch (NoSuchMethodException except) { return getGetterMethod(instanceClass.getSuperclass(), instance, fieldName); } }
From source file:hu.javaforum.util.internal.ReflectionHelper.java
/** * Returns the getter method of the field. It is recursive method. * * @param instanceClass The bean class// w w w .j av a 2 s . c o m * @param instance The bean instance * @param fieldName The field name * @return The getter method, if it is exists * null, if the getter method is not exists */ protected static Method getGetterMethod(final Class instanceClass, final Object instance, final String fieldName) { PerfLogger logger = new PerfLogger(LOGGER); if ("java.lang.Object".equals(instanceClass.getName())) { return null; } try { StringBuilder sb = new StringBuilder(fieldName.length() + GET_WORD.length()); sb.append(GET_WORD); sb.append(fieldName); sb.setCharAt(GET_WORD.length(), Character.toUpperCase(sb.charAt(GET_WORD.length()))); return instanceClass.getDeclaredMethod(sb.toString()); } catch (NoSuchMethodException except) { logger.debug("Invoking %1$s.%2$s() because %3$s", instanceClass.getSuperclass().getName(), fieldName, except.getMessage()); return getGetterMethod(instanceClass.getSuperclass(), instance, fieldName); } }
From source file:com.viettel.util.StringUtils.java
public static String removeVietMarksFast(String text) { StringBuilder sb = new StringBuilder(text); for (int i = 0; i < sb.length(); i++) { sb.setCharAt(i, removeVietMarksFast(sb.charAt(i))); }// ww w . j a v a 2 s. c o m return sb.toString(); }
From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java
/** * Trims any trailing whitespace or the end of Javadoc comment string. * @param builder the StringBuilder to trim. */// ww w . jav a2 s . c o m private static void trimTail(StringBuilder builder) { int index = builder.length() - 1; while (true) { if (Character.isWhitespace(builder.charAt(index))) { builder.deleteCharAt(index); } else if (builder.charAt(index) == '/' && builder.charAt(index - 1) == '*') { builder.deleteCharAt(index); builder.deleteCharAt(index - 1); index--; while (builder.charAt(index - 1) == '*') { builder.deleteCharAt(index - 1); index--; } } else { break; } index--; } }
From source file:org.apache.torque.generator.outlet.java.JavadocOutlet.java
/** * Removes the trailing characters from a string builder. * The characters to be removed are passed in as parameter. * * @param stringBuilder the string builder to remove the end from, not null. * @param removeChars The characters to remove if they appear at the end, * not null.//from ww w . j a v a 2 s . co m */ static void removeEnd(StringBuilder stringBuilder, String removeChars) { Set<Character> removeCharSet = new HashSet<Character>(); for (char character : removeChars.toCharArray()) { removeCharSet.add(character); } int index = stringBuilder.length(); while (index > 0) { if (!removeCharSet.contains(stringBuilder.charAt(index - 1))) { break; } index--; } // index is now last char in String which does not match pattern // maybe -1 if all the string matches or the input is empty stringBuilder.replace(index, stringBuilder.length(), ""); }
From source file:DOMTreeTest.java
public static String characterString(CharacterData node) { StringBuilder builder = new StringBuilder(node.getData()); for (int i = 0; i < builder.length(); i++) { if (builder.charAt(i) == '\r') { builder.replace(i, i + 1, "\\r"); i++;//from ww w.j a v a2 s . co m } else if (builder.charAt(i) == '\n') { builder.replace(i, i + 1, "\\n"); i++; } else if (builder.charAt(i) == '\t') { builder.replace(i, i + 1, "\\t"); i++; } } if (node instanceof CDATASection) builder.insert(0, "CDATASection: "); else if (node instanceof Text) builder.insert(0, "Text: "); else if (node instanceof Comment) builder.insert(0, "Comment: "); return builder.toString(); }
From source file:net.objectlab.kit.util.StringUtil.java
public static String removeTrailingChar(final String original, final char charToRemove) { final StringBuilder builder = new StringBuilder(original); while (builder.length() > 0 && builder.charAt(builder.length() - 1) == charToRemove) { builder.deleteCharAt(builder.length() - 1); }/*from w ww . java 2 s . com*/ return builder.toString(); }
From source file:com.itude.mobile.mobbl.core.util.StringUtilities.java
public static String normalizedPath(String path) { // try to prevent work in the normal case (the path is already normalized) // especially the splitPath method-call is expensive. if (path.indexOf('.') < 0 && path.indexOf("//") < 0) { // remove trailing / if present if (path.endsWith("/")) return path.substring(0, path.length() - 1); else/*from w w w .j a va 2 s.c o m*/ return path; } boolean isRelative = !path.startsWith("/"); StringBuilder result = new StringBuilder(); for (String component : splitPath(path)) { result.append('/').append(component); } if (isRelative && result.length() > 0 && result.charAt(0) == '/') { return result.substring(1); } else { return result.toString(); } }
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static String refactorString(String str) { // Avoid error when content is "" if (str.compareTo("") == 0) { return " "; }/*from w w w. j a va 2 s . com*/ /* * If the font of "\n" is "" or "\n", insert " " in front of it. * * For example: * "\nabc" -> " \nabc" * "\nabc\n\n" -> " \nabc\n \n" */ StringBuilder strBuilder = new StringBuilder(str); int start = 0; int index = strBuilder.indexOf("\n"); while (index != -1) { if (index == 0 || strBuilder.charAt(index - 1) == '\n') { strBuilder.insert(start, " "); start = index + 2; } else { start = index + 1; } if (start > strBuilder.length() || index == strBuilder.length()) { break; } index = strBuilder.indexOf("\n", start); } return strBuilder.toString(); }