List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:com.edgenius.wiki.render.GroupProcessor.java
/** * Insert a group key as macro parameter * @param start /* ww w .j a v a 2s . c o m*/ * @param sb */ public void insertGroupKey(int start, StringBuilder sb) { Macro macro = childrenMap.get(start); if (macro == null) { AuditLogger.error("Unable to find macro in position"); return; } int sep; String first = ":"; String last = ""; for (sep = start; sep < sb.length(); sep++) { char c = sb.charAt(sep); if (c == '}') { break; } if (c == ' ') continue; if (c == ':') { sep++; first = ""; last = "|"; break; } } //insert after macro name, such as "{table" and the space after macro name will be next char of insertion. sb.insert(sep, first + Macro.GROUP_KEY + "=" + getGroupKey(start) + last); }
From source file:edu.chalmers.dat076.moviefinder.service.TitleParser.java
/** * returns next number in mySb and deletes it and everything before it in * mySb./*from www.j a v a 2 s .co m*/ * * @param mySb * @return */ public int getNextNumber(StringBuilder mySb) { int value = -1; boolean deleteAll = true; for (int i = 0; i < mySb.length(); i++) { // Character.isDigit(i) better or worse? if ('0' <= mySb.charAt(i) && mySb.charAt(i) <= '9') { if (value < 0) { value = 0; } else { value = value * 10; } value = value + Character.getNumericValue(mySb.charAt(i)); } else if (value > 0) { mySb.delete(0, i); deleteAll = false; break; } } if (deleteAll && value > 0) { mySb.setLength(0); } return value; }
From source file:net.solarnetwork.web.support.SimpleXmlView.java
private void writeElement(String name, Map<?, ?> props, Writer out, boolean close, ViewResponseAugmentor augmentor) throws IOException { out.write('<'); out.write(name);// w w w . j a v a 2s . c om if (augmentor != null) { augmentor.augmentResponse(out); } Map<String, Object> nested = null; if (props != null) { for (Map.Entry<?, ?> me : props.entrySet()) { String key = me.getKey().toString(); Object val = me.getValue(); if (getPropertySerializerRegistrar() != null) { val = getPropertySerializerRegistrar().serializeProperty(name, val.getClass(), props, val); } if (val instanceof Date) { SimpleDateFormat sdf = SDF.get(); // SimpleDateFormat has no way to create xs:dateTime with tz, // so use trick here to insert required colon for non GMT dates Date date = (Date) val; StringBuilder buf = new StringBuilder(sdf.format(date)); if (buf.charAt(buf.length() - 1) != 'Z') { buf.insert(buf.length() - 2, ':'); } val = buf.toString(); } else if (val instanceof Collection) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (val instanceof Map<?, ?>) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; } else if (classNamesAllowedForNesting != null && !(val instanceof Enum<?>)) { for (String prefix : classNamesAllowedForNesting) { if (val.getClass().getName().startsWith(prefix)) { if (nested == null) { nested = new LinkedHashMap<String, Object>(5); } nested.put(key, val); val = null; break; } } } if (val != null) { // replace & with & String attVal = val.toString(); Matcher matcher = AMP.matcher(attVal); attVal = matcher.replaceAll("&"); attVal = attVal.replace("\"", """); out.write(' '); out.write(key); out.write("=\""); out.write(attVal); out.write('"'); } } } if (close && nested == null) { out.write('/'); } out.write('>'); if (nested != null) { for (Map.Entry<String, Object> me : nested.entrySet()) { outputObject(me.getValue(), me.getKey(), out, augmentor); } if (close) { closeElement(name, out); } } }
From source file:android.pim.vcard.VNodeBuilder.java
private String listToString(List<String> list) { int size = list.size(); if (size > 1) { StringBuilder typeListB = new StringBuilder(); for (String type : list) { typeListB.append(type).append(";"); }/*w w w . j av a2 s. com*/ int len = typeListB.length(); if (len > 0 && typeListB.charAt(len - 1) == ';') { return typeListB.substring(0, len - 1); } return typeListB.toString(); } else if (size == 1) { return list.get(0); } else { return ""; } }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static boolean hasVowel(final CharSequence sequence) { if (isBlankOrNull(sequence)) { return false; }/*from w w w. j a v a 2 s . c om*/ final StringBuilder builder = removeAccentsInternal(sequence); for (int i = 0; i < length(builder); i++) { if (isVowel(builder.charAt(i))) { return true; } } return false; }
From source file:net.yacy.cora.language.phonetic.Metaphone.java
private boolean isPreviousChar(StringBuilder string, int index, char c) { boolean matches = false; if (index > 0 && index < string.length()) { matches = string.charAt(index - 1) == c; }//from w w w . j ava 2 s .c om return matches; }
From source file:org.exjello.mail.Exchange2003Connection.java
private static String escape(String url) { StringBuilder collector = new StringBuilder(url); for (int i = collector.length() - 1; i >= 0; i--) { int value = (int) collector.charAt(i); if (value > 127 || !ALLOWED_CHARS[value]) { collector.deleteCharAt(i);//from w w w . j a v a2 s .co m collector.insert(i, HEXABET[value & 0x0f]); value >>>= 4; collector.insert(i, HEXABET[value & 0x0f]); value >>>= 4; collector.insert(i, '%'); if (value > 0) { collector.insert(i, HEXABET[value & 0x0f]); value >>>= 4; collector.insert(i, HEXABET[value & 0x0f]); collector.insert(i, '%'); } } } return collector.toString(); }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static boolean hasConsonant(final CharSequence sequence) { if (isBlankOrNull(sequence)) { return false; }//from w w w.j av a 2s.co m final StringBuilder builder = removeAccentsInternal(sequence); for (int i = 0; i < length(builder); i++) { if (isConsonant(builder.charAt(i))) { return true; } } return false; }
From source file:io.codis.nedis.handler.RedisResponseDecoder.java
private String decodeString(ByteBuf in) throws ProtocolException { final StringBuilder buffer = new StringBuilder(); final MutableBoolean reachCRLF = new MutableBoolean(false); setReaderIndex(in, in.forEachByte(new ByteBufProcessor() { @Override//w ww .jav a 2s. c o m public boolean process(byte value) throws Exception { if (value == '\n') { if ((byte) buffer.charAt(buffer.length() - 1) != '\r') { throw new ProtocolException("Response is not ended by CRLF"); } else { buffer.setLength(buffer.length() - 1); reachCRLF.setTrue(); return false; } } else { buffer.append((char) value); return true; } } })); return reachCRLF.booleanValue() ? buffer.toString() : null; }
From source file:com.github.brandtg.pantopod.crawler.CrawlingEventHandler.java
private URI getNextUri(URI url, String href, String chroot) throws Exception { // if (href.contains("..")) { ////from w w w. j a v a2 s.c o m // throw new IllegalArgumentException("Relative URI not allowed: " + href); // } URI hrefUri = URI.create(href.trim().replaceAll(" ", "+")); URIBuilder builder = new URIBuilder(); builder.setScheme(hrefUri.getScheme() == null ? url.getScheme() : hrefUri.getScheme()); builder.setHost(hrefUri.getHost() == null ? url.getHost() : hrefUri.getHost()); builder.setPort(hrefUri.getPort() == -1 ? url.getPort() : hrefUri.getPort()); if (hrefUri.getPath() != null) { StringBuilder path = new StringBuilder(); if (hrefUri.getHost() == null && chroot != null) { path.append(chroot); } // Ensure no two slashes if (hrefUri.getPath() != null && hrefUri.getPath().length() > 0 && hrefUri.getPath().charAt(0) == '/' && path.length() > 0 && path.charAt(path.length() - 1) == '/') { path.setLength(path.length() - 1); } path.append(hrefUri.getPath()); builder.setPath(chroot == null ? "" : chroot + hrefUri.getPath()); } if (hrefUri.getQuery() != null) { builder.setCustomQuery(hrefUri.getQuery()); } if (hrefUri.getFragment() != null) { builder.setFragment(hrefUri.getFragment()); } return builder.build(); }