Example usage for java.lang StringBuilder charAt

List of usage examples for java.lang StringBuilder charAt

Introduction

In this page you can find the example usage for java.lang StringBuilder charAt.

Prototype

char charAt(int index);

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:net.yacy.cora.language.phonetic.Metaphone.java

private boolean isVowel(StringBuilder string, int index) {
    return VOWELS.indexOf(string.charAt(index)) >= 0;
}

From source file:com.htmlhifive.tools.codeassist.core.proposal.build.ObjectLiteralCodeBuilder.java

@Override
protected void buildEnd(StringBuilder sb, StringBuilder part, int tempInsertPosition) {

    // ?/*from   www  .j  a va2  s.c o m*/
    boolean delflg = true;
    int deletePosition = 0;
    int insertPosition = tempInsertPosition;
    for (int currentPosition = insertPosition - 1; currentPosition > 0; currentPosition--) {
        if (sb.charAt(currentPosition) == ',') {
            deletePosition = currentPosition;
            break;
        }
        if (CharUtils.isAsciiPrintable(sb.charAt(currentPosition))) {
            delflg = false;
            break;
        }
    }
    // while (sb.charAt(currentPosition) != ',') {
    // currentPosition--;
    // System.out.println(sb.charAt(currentPosition));
    // }
    if (delflg) {
        insertPosition--;
        sb.deleteCharAt(deletePosition);
    }
    super.buildEnd(sb, part, insertPosition);
}

From source file:net.sf.jabb.util.db.impl.DbcpDataSourceProvider.java

public DataSource createDataSource(String source, String config) {
    String[] cfgs = config.split(PropertiesLoader.DELIMITERS, 2);
    if (cfgs.length != 2) {
        log.warn("Wrong configuration format for '" + source + "' : " + config);
        return null;
    }//w  w w.j a v a  2  s .c o  m

    DataSource ds = null;

    try {
        DirectDataSourceConfiguration lowerConfig = new DirectDataSourceConfiguration(cfgs[0]);
        Class.forName(lowerConfig.getDriverClassName());

        Properties props = propLoader.load(cfgs[1]);
        Properties connProps = lowerConfig.getConnectionProperties();
        props.put("username", connProps.get("user"));
        connProps.remove("user");
        props.put("password", connProps.get("password"));
        connProps.remove("password");
        props.put("url", lowerConfig.getUrl());
        props.put("driverClassName", lowerConfig.getDriverClassName());

        StringBuilder sb = new StringBuilder();
        String oldConnProp = props.getProperty("connectionProperties");
        if (oldConnProp != null) {
            sb.append(oldConnProp.trim());
        }
        for (Map.Entry<Object, Object> p : connProps.entrySet()) {
            if (sb.length() > 0 && sb.charAt(sb.length() - 1) != ';') {
                sb.append(';');
            }
            sb.append(p.getKey().toString());
            sb.append('=');
            sb.append(p.getValue().toString());
        }
        props.put("connectionProperties", sb.toString());

        ds = BasicDataSourceFactory.createDataSource(props);

    } catch (InvalidPropertiesFormatException e) {
        log.warn(
                "Wrong configuration properties file format for '" + source + "' with configuration: " + config,
                e);
    } catch (IOException e) {
        log.warn("Error loading configuration file for '" + source + "' with configuration: " + config, e);
    } catch (ClassNotFoundException e) {
        log.warn("Driver class not found for '" + source + "' with configuration: " + config, e);
    } catch (Exception e) {
        log.warn("Error creating data source for '" + source + "' with configuration: " + config, e);
    }

    return ds;
}

From source file:com.aionengine.gameserver.cache.HTMLCache.java

private String compactHtml(StringBuilder sb, String html) {
    sb.setLength(0);//from w  w  w. j ava2s .c o m
    sb.append(html);

    for (int i = 0; i < sb.length(); i++)
        if (Character.isWhitespace(sb.charAt(i)))
            sb.setCharAt(i, ' ');

    replaceAll(sb, "  ", " ");

    replaceAll(sb, "< ", "<");
    replaceAll(sb, " >", ">");

    for (int i = 0; i < TAGS_TO_COMPACT.length; i += 3) {
        replaceAll(sb, TAGS_TO_COMPACT[i + 1], TAGS_TO_COMPACT[i]);
        replaceAll(sb, TAGS_TO_COMPACT[i + 2], TAGS_TO_COMPACT[i]);
    }

    replaceAll(sb, "  ", " ");

    // String.trim() without additional garbage
    int fromIndex = 0;
    int toIndex = sb.length();

    while (fromIndex < toIndex && sb.charAt(fromIndex) == ' ')
        fromIndex++;

    while (fromIndex < toIndex && sb.charAt(toIndex - 1) == ' ')
        toIndex--;

    return sb.substring(fromIndex, toIndex);
}

From source file:com.example.phonetic.KoelnerPhonetik.java

private String removeSequences(String str) {
    if (str == null || str.length() == 0) {
        return "";
    }//  w  w w  . j  a va 2 s.  co  m
    int i = 0, j = 0;
    StringBuilder sb = new StringBuilder().append(str.charAt(i++));
    char c;
    while (i < str.length()) {
        c = str.charAt(i);
        if (c != sb.charAt(j)) {
            sb.append(c);
            j++;
        }
        i++;
    }
    return sb.toString();
}

From source file:org.ambraproject.util.TextUtils.java

/**
   * Given a string, and the index to start looking at, find the index of the start of the scheme. Eg.
 * <pre>/*ww w  . j  a  v a  2  s  .  c om*/
 * getSchemeIndex("notes://abc", 0) -> 0
 * getSchemeIndex("abc notes://abc", 0) -> 4
 * </pre>
 * @param str    The string to search for
 * @param startIndex   Where to start looking at
 * @return The location the string was found, ot -1 if the string was not found.
 */
private static int getSchemeIndex(StringBuilder str, int startIndex) {
    int schemeIndex = str.indexOf(UrlUtils.SCHEME_URL, startIndex + 1);

    //if it was not found, or found at the start of the string, then return 'not found'
    if (schemeIndex <= 0) {
        return -1;
    }

    //walk backwards through the scheme until we find the first non valid character
    int schemeStart;

    for (schemeStart = schemeIndex - 1; schemeStart >= 0; schemeStart--) {
        char currentChar = str.charAt(schemeStart);

        if (!UrlUtils.isValidSchemeChar(currentChar)) {
            break;
        }
    }

    //reset the scheme to the starting character
    schemeStart++;

    /*
         we don't want to do this, otherwise an invalid scheme would ruin the linking for later schemes
        if (UrlUtils.isValidScheme(str.substring(schemeStart, schemeIndex)))
            return schemeStart;
        else
            return -1;
    */
    return schemeStart;
}

From source file:com.epam.dlab.module.ParserCsv.java

@Override
public List<String> parseRow(String line) throws ParseException {
    int realPos = 0;
    int pos = 0;/*from   w  ww .java2s .c  o m*/
    boolean isDelimiter = false;
    StringBuilder sb = new StringBuilder(line);
    List<String> row = new ArrayList<String>();

    while (pos < sb.length()) {
        char c = sb.charAt(pos);
        /*
        LOGGER.debug("Current buffer {}", sb);
        LOGGER.debug("pos {}", pos);
        LOGGER.debug("isDelimiter {}", isDelimiter);
        */
        if (c == escapeChar) {
            realPos++;
            pos++;
            if (pos == sb.length()) {
                throw getParseException("Invalid escape char", realPos, line);
            }
            sb.delete(pos - 1, pos);
            realPos++;
        } else if (c == fieldTerminator) {
            realPos++;
            if (isDelimiter) {
                realPos++;
                pos++;
                if (pos == sb.length()) {
                    sb.delete(pos - 1, pos);
                    break;
                }
                if (sb.charAt(pos) == fieldSeparator) {
                    row.add(sb.substring(0, pos - 1));
                    sb.delete(0, pos + 1);
                    pos = 0;
                    isDelimiter = false;
                    continue;
                }
                throw getParseException("Invalid field delimiter", realPos, line);
            }

            if (pos != 0) {
                throw getParseException("Unterminated field", realPos, line);
            }
            sb.delete(0, 1);
            isDelimiter = true;
            continue;
        } else if (c == fieldSeparator) {
            realPos++;
            if (isDelimiter) {
                pos++;
                continue;
            }
            row.add(sb.substring(0, pos));
            sb.delete(0, pos + 1);
            pos = 0;
        } else {
            realPos++;
            pos++;
        }
    }
    row.add(sb.toString());

    return row;
}

From source file:com.prowidesoftware.swift.model.IBAN.java

/**
 * Translate letters to numbers, also ignoring non alphanumeric characters
 *
 * @param bban//from w  ww . j  a v  a2 s. com
 * @return the translated value
 */
public String translateChars(final StringBuilder bban) {
    final StringBuilder result = new StringBuilder();
    for (int i = 0; i < bban.length(); i++) {
        char c = bban.charAt(i);
        if (Character.isLetter(c)) {
            result.append(Character.getNumericValue(c));
        } else {
            result.append((char) c);
        }
    }
    return result.toString();
}

From source file:org.gradle.groovy.scripts.AbstractUriScriptSource.java

/**
 * Returns the class name for use for this script source.  The name is intended to be unique to support mapping
 * class names to source files even if many sources have the same file name (e.g. build.gradle).
 *//*from  w  ww.  j a v  a 2 s.c o m*/
public String getClassName() {
    if (className == null) {
        URI sourceUri = getResource().getURI();
        String name = StringUtils.substringBeforeLast(StringUtils.substringAfterLast(sourceUri.toString(), "/"),
                ".");
        StringBuilder className = new StringBuilder(name.length());
        for (int i = 0; i < name.length(); i++) {
            char ch = name.charAt(i);
            if (Character.isJavaIdentifierPart(ch)) {
                className.append(ch);
            } else {
                className.append('_');
            }
        }
        if (!Character.isJavaIdentifierStart(className.charAt(0))) {
            className.insert(0, '_');
        }
        className.setLength(Math.min(className.length(), 30));
        className.append('_');
        String path = sourceUri.toString();
        className.append(HashUtil.createCompactMD5(path));

        this.className = className.toString();
    }

    return className;
}

From source file:com.aionemu.gameserver.cache.HTMLCache.java

private String compactHtml(StringBuilder sb, String html) {
    sb.setLength(0);/*  ww  w  . j  a v a  2 s . co  m*/
    sb.append(html);

    for (int i = 0; i < sb.length(); i++) {
        if (Character.isWhitespace(sb.charAt(i))) {
            sb.setCharAt(i, ' ');
        }
    }

    replaceAll(sb, "  ", " ");

    replaceAll(sb, "< ", "<");
    replaceAll(sb, " >", ">");

    for (int i = 0; i < TAGS_TO_COMPACT.length; i += 3) {
        replaceAll(sb, TAGS_TO_COMPACT[i + 1], TAGS_TO_COMPACT[i]);
        replaceAll(sb, TAGS_TO_COMPACT[i + 2], TAGS_TO_COMPACT[i]);
    }

    replaceAll(sb, "  ", " ");

    // String.trim() without additional garbage
    int fromIndex = 0;
    int toIndex = sb.length();

    while (fromIndex < toIndex && sb.charAt(fromIndex) == ' ') {
        fromIndex++;
    }

    while (fromIndex < toIndex && sb.charAt(toIndex - 1) == ' ') {
        toIndex--;
    }

    return sb.substring(fromIndex, toIndex);
}