Example usage for java.lang StringBuffer charAt

List of usage examples for java.lang StringBuffer charAt

Introduction

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

Prototype

@Override
public synchronized char charAt(int index) 

Source Link

Usage

From source file:Main.java

public static String removeBlanks(String content) {
    if (content == null) {
        return null;
    }/*  w  w  w .  jav  a  2  s. c o m*/
    StringBuffer buff = new StringBuffer();
    buff.append(content);
    for (int i = buff.length() - 1; i >= 0; i--) {
        if (' ' == buff.charAt(i) || ('\n' == buff.charAt(i)) || ('\t' == buff.charAt(i))
                || ('\r' == buff.charAt(i))) {
            buff.deleteCharAt(i);
        }
    }
    return buff.toString();
}

From source file:Main.java

public static String getXmlEncoded(String text) {
    StringBuffer buf = new StringBuffer(text);
    for (int i = 0; i < buf.length(); ++i) {
        char c = buf.charAt(i);
        if (c == '&') {
            buf.replace(i, i + 1, "&amp;");
        } else if (c == '<') {
            buf.replace(i, i + 1, "&lt;");
        } else if (c == '>') {
            buf.replace(i, i + 1, "&gt;");
        } else if (c == '"') {
            buf.replace(i, i + 1, "&quot;");
        } else if (c == '\'') {
            buf.replace(i, i + 1, "&#39;");
        }/*w w w.j ava2s .c om*/
    }
    return buf.toString();
}

From source file:Main.java

public static String getSringBeforeChar(String sourceStr, char ch) {
    StringBuffer sb = new StringBuffer(sourceStr);
    StringBuffer newSb = new StringBuffer();
    for (int i = 0; i < sb.length(); i++) {
        if (sb.charAt(i) == ch) {
            break;
        }/*  w ww.ja v a  2s .  c o m*/
        newSb.append(sb.charAt(i));
    }

    return newSb.toString();

}

From source file:Main.java

/**
 * Return true if the string starting at offset in sb matches with xmlTag.
 * @param sb StringBuffer//from   w ww  .j a  v  a  2s  . c  om
 * @param offset int
 * @param xmlTag String The XML tag name to check without '&lt;' and '&gt;'
 * @return
 */
private static boolean matchXMLTag(StringBuffer sb, int offset, String xmlTag) {
    if (offset >= sb.length()) {
        return false;
    }
    if (sb.charAt(offset) != '<') {
        return false;
    }
    int indexOfSpace = sb.indexOf(" ", offset);
    int indexOfGt = sb.indexOf(">", offset);
    int indexOfEndTag = Integer.MAX_VALUE;
    if (indexOfSpace >= 0) {
        indexOfEndTag = indexOfSpace;
    }
    if (indexOfGt >= 0 && indexOfGt < indexOfEndTag) {
        indexOfEndTag = indexOfGt;
    }
    if (indexOfEndTag == Integer.MAX_VALUE) {
        return false;
    }
    String potentialTag = sb.substring(offset + 1, indexOfEndTag);
    return potentialTag.equals(xmlTag);
}

From source file:org.objectweb.proactive.extensions.vfsprovider.client.ProActiveFileNameParser.java

private static String extractServicePath(StringBuffer path) throws FileSystemException {
    if (path.length() > 0 && path.charAt(0) != FileName.SEPARATOR_CHAR) {
        throw new FileSystemException(
                "Invalid path in URI: service path after host name does not begin with slash");
    }//  w  w w. ja v a 2  s. c o  m

    int idx = path.indexOf(ProActiveFileName.SERVICE_AND_FILE_PATH_SEPARATOR);
    if (idx == -1) {
        // simply assume that whole path is a service path
        final String servicePath = path.toString();
        path.delete(0, path.length());
        return servicePath;
    }
    final String servicePath = path.substring(0, idx);
    path.delete(0, idx + ProActiveFileName.SERVICE_AND_FILE_PATH_SEPARATOR.length());
    return servicePath;
}

From source file:Main.java

/**
 * Convert entities to umlaute//from w  w w.  java2s. c  o m
 */
public static String decode(String value) {
    StringBuffer buffer = new StringBuffer(value);
    int pos;
    boolean found;
    for (int i = 0; i < buffer.length(); i++) {
        if (buffer.charAt(i) == '_' && buffer.charAt(i + 1) == '_') {
            pos = i + 2;
            found = false;
            while (buffer.charAt(pos) >= '0' && buffer.charAt(pos) <= '9') {
                found = true;
                pos++;
            }
            if (found == true && pos > i + 2 && buffer.charAt(pos) == ';') {
                int ent = new Integer(buffer.substring(i + 2, pos)).intValue();
                buffer.replace(i, pos + 1, "" + (char) ent);
            }
        }
    }
    return buffer.toString();
}

From source file:Utils.java

/**
 * Add two URI path segments. Handles null and empty paths, path and query
 * params (eg ?a=b or ;JSESSIONID=xxx) and avoids duplicate '/'
 * //  w ww.  ja v a  2 s  .c o m
 * @param p1
 *          URI path segment
 * @param p2
 *          URI path segment
 * @return Legally combined path segments.
 */
public static String addPaths(String p1, String p2) {
    if (p1 == null || p1.length() == 0) {
        if (p1 != null && p2 == null)
            return p1;
        return p2;
    }
    if (p2 == null || p2.length() == 0)
        return p1;

    int split = p1.indexOf(';');
    if (split < 0)
        split = p1.indexOf('?');
    if (split == 0)
        return p2 + p1;
    if (split < 0)
        split = p1.length();

    StringBuffer buf = new StringBuffer(p1.length() + p2.length() + 2);
    buf.append(p1);

    if (buf.charAt(split - 1) == '/') {
        if (p2.startsWith(SLASH)) {
            buf.deleteCharAt(split - 1);
            buf.insert(split - 1, p2);
        } else
            buf.insert(split, p2);
    } else {
        if (p2.startsWith(SLASH))
            buf.insert(split, p2);
        else {
            buf.insert(split, '/');
            buf.insert(split + 1, p2);
        }
    }

    return buf.toString();
}

From source file:org.gluu.oxtrust.util.PropertyUtil.java

/**
 * Inserts a backslash before every comma
 *///from ww w . ja v a2  s  . c  om
private static String escapeComma(String s) {
    StringBuffer buf = new StringBuffer(s);
    for (int i = 0; i < buf.length(); i++) {
        char c = buf.charAt(i);
        if (c == ',') {
            buf.insert(i, '\\');
            i++;
        }
    }
    return buf.toString();
}

From source file:XMLCharacterRecognizer.java

/**
 * Tell if the string is whitespace./*from   w  ww . j av  a2s.  com*/
 *
 * @param buf StringBuffer to check as XML whitespace.
 * @return True if characters in buffer are XML whitespace, false otherwise
 */
public static boolean isWhiteSpace(StringBuffer buf) {

    int n = buf.length();

    for (int i = 0; i < n; i++) {
        if (!isWhiteSpace(buf.charAt(i)))
            return false;
    }

    return true;
}

From source file:fr.cls.atoll.motu.library.converter.jaxb.LocaleAdapter.java

/**
 * Trim all occurences of the supplied leading character from the given String.
 * /*  w  w w .  j a  v  a 2  s. co  m*/
 * @param str the String to check
 * @param leadingCharacter the leading character to be trimmed
 * @return the trimmed String
 */
private static String trimLeadingCharacter(String str, char leadingCharacter) {
    if (StringUtils.isEmpty(str)) {
        return str;
    }
    StringBuffer buf = new StringBuffer(str);
    while (buf.length() > 0 && buf.charAt(0) == leadingCharacter) {
        buf.deleteCharAt(0);
    }
    return buf.toString();
}