List of usage examples for java.lang StringBuilder deleteCharAt
@Override public StringBuilder deleteCharAt(int index)
From source file:com.forerunnergames.tools.common.Strings.java
/** * Deletes the last character from the specified StringBuilder. * * @param s// w w w. j a v a 2s . c o m * The StringBuilder from which to delete the last character, must not be null, may be empty. * * @return The StringBuilder with its last character deleted and any remaining characters shifted left, or the * original StringBuilder if it was already empty. */ public static StringBuilder deleteLastChar(final StringBuilder s) { Arguments.checkIsNotNull(s, "s"); return s.length() > 0 ? s.deleteCharAt(s.length() - 1) : s; }
From source file:com.edgenius.wiki.render.MarkupUtil.java
/** * Simply replace all filter keywords with leading odd number slash "\" by Hiding character, now it is "HH". * It is useful while only detect if the valid filter exist or not, or get length Index value of valid filter (as the * replacement does not change the content length) * @param text//from w w w.j ava 2s .c om * @return */ public static CharSequence hideEscapeMarkup(String input) { if (input == null) return new StringBuilder(); int len = input.length(); StringBuilder sb = new StringBuilder(); int slash = 0; boolean odd; int currLen; for (int idx = 0; idx < len; idx++) { char c = input.charAt(idx); if (c == '\\') { slash++; sb.append(c); continue; } odd = slash % 2 != 0; //even ">" is not filter pattern keyword, but it use in markup link. // For example[view has \\> char>link],here must escape \> to entity, then in LinkFilter could correctly convert \&#(int >); // to ">", as it will call unescapeMarkupLink() to remove another "\" if (StringUtils.contains(FilterRegxConstants.FILTER_KEYWORD + ">", c) && odd) { currLen = sb.length() - 1; sb.deleteCharAt(currLen); //delete last slash sb.append(HIDE_TOKEN); } else sb.append(c); slash = 0; } return sb; }
From source file:com.adguard.commons.web.UrlUtils.java
/** * Gets all possible domain names up to 2nd level. * <p/>//from w w w. j a v a 2s. c o m * For example, for "test.domain.name.com" * this method will return:<br/> * name.com * domain.name.com * test.domain.name.com * * @param domainName Domain name to extract * @return List of possible domain names */ public static List<String> getTopDomainNames(String domainName) { String[] parts = StringUtils.split(domainName, "."); if (parts == null || parts.length <= 1) { return Arrays.asList(domainName); } List<String> domainNames = new ArrayList<>(); for (int i = 0; i < parts.length - 1; i++) { StringBuilder sb = new StringBuilder(); for (int j = 0; j + i < parts.length; j++) { sb.append(parts[j + i]); sb.append("."); } sb.deleteCharAt(sb.length() - 1); domainNames.add(sb.toString()); } return domainNames; }
From source file:gov.nih.nci.cabig.ccts.hibernate.NamingStrategy.java
private String pluralize(String name) { StringBuilder p = new StringBuilder(name); if (name.endsWith("y")) { p.deleteCharAt(p.length() - 1); p.append("ies"); } else {/*from www .j av a 2 s . c o m*/ p.append('s'); } return p.toString(); }
From source file:de.tudarmstadt.ukp.clarin.webanno.crowdflower.NamedEntityTaskManager.java
/** * Helper function to concatenate a list of strings with the supplied separator * {"item","item3","test"} -> "item,item3,test" * * @param words the words.// www .jav a2 s . c om * @param separator the separator. * @return string the result. */ private static String concatWithSeparator(Collection<String> words, String separator) { StringBuilder wordList = new StringBuilder(); for (String word : words) { wordList.append(new String(word) + separator); } return new String(wordList.deleteCharAt(wordList.length() - 1)); }
From source file:gumga.framework.presentation.api.CSVGeneratorAPI.java
public static StringBuilder objectToCsvLine(Object gm) { StringBuilder sb = new StringBuilder(); for (Field f : getAllAtributes(gm.getClass())) { try {/* w w w .j ava 2 s. c o m*/ f.setAccessible(true); if (f.get(gm) != null) { Field idField = getIdField(f.getType()); if (idField != null) { idField.setAccessible(true); Object idValue = idField.get(f.get(gm)); sb.append(idValue.toString()); } else if (f.getType().equals(Date.class)) { sb.append(SDF.format(f.get(gm))); } else { sb.append(f.get(gm).toString()); } } } catch (Exception ex) { log.error("erro ao criar linha csv", ex); } sb.append(CSV_SEPARATOR); } sb.deleteCharAt(sb.length() - 1); sb.append(CSV_LINE_DELIMITER); return sb; }
From source file:com.qycloud.oatos.license.utils.LicenseUtil.java
private String getSignature(String str) { StringBuilder sign = new StringBuilder(str); for (int i = chars.length; i > 0; i--) { sign.deleteCharAt(chars[i - 1]); }/*from w w w . j av a2 s . c om*/ return sign.toString(); }
From source file:com.lixiaocong.aspect.LoggerAspect.java
@Before("execution(* com.lixiaocong.controller..*(..)) || execution(* com.lixiaocong.service..*(..)) || execution(* com.lixiaocong.repository..*(..))") public void befor(JoinPoint point) { Object[] signatureArgs = point.getArgs(); if (signatureArgs.length == 0) { logger.info(point.getSignature() + " called"); return;//from w w w . ja va 2 s . c o m } StringBuilder sb = new StringBuilder(); for (Object signatureArg : signatureArgs) { sb.append(signatureArg).append(","); } sb.deleteCharAt(sb.length() - 1); logger.info(point.getSignature() + " called with args:" + sb.toString()); }
From source file:com.springrts.springls.Client.java
/** * Removes carriage-return chars (first part of windows EOL "\r\n"). * @param str where to search in/* w w w . j av a 2 s .com*/ * @param posUntil only chars from 0 until this position are searched * @return number of deleted chars */ private static int deleteCarriageReturnChars(StringBuilder str, int posUntil) { int deleted = 0; int rPos = str.lastIndexOf("\r", posUntil); while (rPos != -1) { str.deleteCharAt(rPos); deleted++; rPos = str.lastIndexOf("\r", rPos); } return deleted; }
From source file:com.marklogic.contentpump.utilities.OptionsFileUtil.java
/** * Expands any options file that may be present in the given set of arguments. * * @param args the given arguments/* www . j a va2 s . c om*/ * @return a new string array that contains the expanded arguments. * @throws Exception */ public static String[] expandArguments(String[] args) throws Exception { List<String> options = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { if (args[i].equals(OPTIONS_FILE)) { if (i == args.length - 1) { throw new Exception("Missing options file"); } String fileName = args[++i]; File optionsFile = new File(fileName); BufferedReader reader = null; StringBuilder buffer = new StringBuilder(); try { reader = new BufferedReader(new FileReader(optionsFile)); String nextLine = null; while ((nextLine = reader.readLine()) != null) { nextLine = nextLine.trim(); if (nextLine.length() == 0 || nextLine.startsWith("#")) { // empty line or comment continue; } buffer.append(nextLine); if (nextLine.endsWith("\\")) { if (buffer.charAt(0) == '\'' || buffer.charAt(0) == '"') { throw new Exception("Multiline quoted strings not supported in file(" + fileName + "): " + buffer.toString()); } // Remove the trailing back-slash and continue buffer.deleteCharAt(buffer.length() - 1); } else { // The buffer contains a full option options.add(removeQuotesEncolosingOption(fileName, buffer.toString())); buffer.delete(0, buffer.length()); } } // Assert that the buffer is empty if (buffer.length() != 0) { throw new Exception( "Malformed option in options file(" + fileName + "): " + buffer.toString()); } } catch (IOException ex) { throw new Exception("Unable to read options file: " + fileName, ex); } finally { if (reader != null) { try { reader.close(); } catch (IOException ex) { LOG.info("Exception while closing reader", ex); } } } } else { // Regular option. Parse it and put it on the appropriate list options.add(args[i]); } } return options.toArray(new String[options.size()]); }