Example usage for java.text StringCharacterIterator next

List of usage examples for java.text StringCharacterIterator next

Introduction

In this page you can find the example usage for java.text StringCharacterIterator next.

Prototype

public char next() 

Source Link

Document

Implements CharacterIterator.next() for String.

Usage

From source file:org.getobjects.eoaccess.EOAdaptor.java

public boolean escapeIntoBuffer(final StringBuilder _sb, final String _value, final char _quoteChar) {
    if (_value == null)
        return false;

    StringCharacterIterator localParser = new StringCharacterIterator(_value);

    for (char c = localParser.current(); c != CharacterIterator.DONE; c = localParser.next()) {
        if (c == _quoteChar) {
            // TBD: buggy? Just quotes single-quotes?
            _sb.append('\'');
            _sb.append('\'');
        } else if (c == '\\') { // escape backslash with double-backslash (why?)
            _sb.append('\\');
            _sb.append('\\');
        } else//www .ja va 2 s . c o m
            _sb.append(c);
    }

    return true;
}

From source file:org.getobjects.eoaccess.EOSQLExpression.java

/**
 * This function escapes single quotes and backslashes with itself. Eg:<pre>
 *   Hello 'World'//from w  w  w .j a  v  a2  s . com
 *   Hello ''World''</pre>
 * @param _value - String to escape
 * @return escaped String
 */
public static String escapeSQLString(final String _value) {
    if (_value == null)
        return null;
    if (_value.length() == 0)
        return "";

    final StringBuilder buffer = new StringBuilder(_value.length() + 8);
    final StringCharacterIterator localParser = new StringCharacterIterator(_value);

    // slow
    for (char c = localParser.current(); c != CharacterIterator.DONE; c = localParser.next()) {
        if (c == '\'') { // replace ' with ''
            buffer.append('\'');
            buffer.append('\'');
        } else if (c == '\\') { // replace \ with \\
            buffer.append('\\');
            buffer.append('\\');
        } else
            buffer.append(c);
    }
    return buffer.toString();
}

From source file:org.hyperic.hq.ui.action.resource.common.monitor.visibility.IndicatorChartsAction.java

/**
 * Find characters having special meaning <em>inside</em> HTML tags and
 * URLs./*from  w w w  .  j a v a2s.  co  m*/
 * 
 * <P>
 * The special characters are :
 * <ul>
 * <li><
 * <li>>
 * <li>"
 * <li>'
 * <li>\
 * <li>&
 * <li>|
 * <li>?
 * </ul>
 * 
 * <P>
 */
private int indexOfSpecialChars(String aTagFragment) {
    final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);

    int i = 0;
    for (char character = iterator.current(); character != StringCharacterIterator.DONE; character = iterator
            .next(), i++) {
        switch (character) {
        case '<':
        case '>':
        case '\"':
        case '\'':
        case '\\':
        case '&':
        case '|':
        case '?':
            return i;
        default:
            break;
        }
    }
    return -1;
}

From source file:org.hyperic.hq.ui.util.SaveChartToDashboardUtil.java

/**
 * Replace characters having special meaning <em>inside</em> HTML tags
 * with their escaped equivalents, using character entities such as
 * <tt>'&amp;'</tt>.//from   ww w .ja  v a2 s .c om
 * 
 * <P>
 * The escaped characters are :
 * <ul>
 * <li><
 * <li>>
 * <li>"
 * <li>'
 * <li>\
 * <li>&
 * </ul>
 * 
 * <P>
 * This method ensures that arbitrary text appearing inside a tag does not
 * "confuse" the tag. For example, <tt>HREF='Blah.do?Page=1&Sort=ASC'</tt>
 * does not comply with strict HTML because of the ampersand, and should be
 * changed to <tt>HREF='Blah.do?Page=1&amp;Sort=ASC'</tt>. This is
 * commonly seen in building query strings. (In JSTL, the c:url tag performs
 * this task automatically.)
 */
private static String forHTMLTag(String aTagFragment) {
    final StringBuffer result = new StringBuffer();

    final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);

    for (char character = iterator.current(); character != StringCharacterIterator.DONE; character = iterator
            .next()) {
        switch (character) {
        case '<':
            result.append("&lt;");
            break;
        case '>':
            result.append("&gt;");
            break;
        case '\"':
            result.append("&quot;");
            break;
        case '\'':
            result.append("&#039;");
            break;
        case '\\':
            result.append("&#092;");
            break;
        case '&':
            result.append("&amp;");
            break;
        case '|':
            result.append("&#124;");
            break;
        case ',':
            result.append("&#44;");
            break;
        default:
            //the char is not a special one add it to the result as is
            result.append(character);
            break;
        }
    }
    return result.toString();
}

From source file:org.rhq.enterprise.gui.legacy.action.resource.common.monitor.visibility.IndicatorChartsAction.java

/**
 * Find characters having special meaning <em>inside</em> HTML tags and URLs.
 * <p/>//from   w  ww  . j  a  va 2  s  . c om
 * <p/>
 * The special characters are : <ul> <li>< <li>> <li>" <li>' <li>\ <li>& <li>| <li>? </ul>
 * <p/>
 * <p/>
 */
private static int indexOfSpecialChars(String aTagFragment) {
    final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);

    int i = 0;
    for (char character = iterator.current(); character != CharacterIterator.DONE; character = iterator
            .next(), i++) {
        switch (character) {
        case '<':
        case '>':
        case '\"':
        case '\'':
        case '\\':
        case '&':
        case '|':
        case '?':
            return i;
        default:
            break;
        }
    }
    return -1;
}

From source file:org.rhq.enterprise.gui.legacy.action.resource.common.monitor.visibility.ViewChartAction.java

/**
 * Replace characters having special meaning <em>inside</em> HTML tags with
 * their escaped equivalents, using character entities such as
 * <tt>'&amp;'</tt>./*from   w  w w  . j  a v a 2s .  c o  m*/
 * <P>
 * The escaped characters are :
 * <ul>
 * <li><
 * <li>>
 * <li>"
 * <li>'
 * <li>\
 * <li>&
 * </ul>
 * <P>
 * This method ensures that arbitrary text appearing inside a tag does not
 * "confuse" the tag. For example, <tt>HREF='Blah.do?Page=1&Sort=ASC'</tt>
 * does not comply with strict HTML because of the ampersand, and should be
 * changed to <tt>HREF='Blah.do?Page=1&amp;Sort=ASC'</tt>. This is
 * commonly seen in building query strings. (In JSTL, the c:url tag performs
 * this task automatically.)
 * 
 * @param aTagFragment
 *           some HTML to be escaped
 * @return escaped HTML
 */
private static String forHTMLTag(String aTagFragment) {
    final StringBuffer result = new StringBuffer();

    final StringCharacterIterator iterator = new StringCharacterIterator(aTagFragment);

    for (char character = iterator.current(); character != CharacterIterator.DONE; character = iterator
            .next()) {
        switch (character) {
        case '<':
            result.append("&lt;");
            break;
        case '>':
            result.append("&gt;");
            break;
        case '\"':
            result.append("&quot;");
            break;
        case '\'':
            result.append("&#039;");
            break;
        case '\\':
            result.append("&#092;");
            break;
        case '&':
            result.append("&amp;");
            break;
        case '|':
            result.append("&#124;");
            break;
        case ',':
            result.append("&#44;");
            break;
        default:
            // the char is not a special one add it to the result as is
            result.append(character);
            break;
        }
    }
    return result.toString();
}

From source file:org.squale.welcom.outils.Util.java

public final static String formatFile(String st) {
    // Transforme les lettres accentues
    st = Util.formatAccent(st);/* www.ja  va2s.  co  m*/

    final StringCharacterIterator iter = new StringCharacterIterator(st);
    final StringBuffer sb = new StringBuffer();

    for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
        if (!(((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'z'))
                || (((c >= 'A') && (c <= 'Z')) || (c == '.')))) {
            sb.append('_');
        } else {
            sb.append(c);
        }
    }

    return sb.toString();
}

From source file:org.squale.welcom.outils.Util.java

public static String formatJavaScript(String st) {
    if (st == null) {
        return "";
    }//from  w w  w. j a  v a  2s. c o  m

    st = st.replaceAll("\r\n", "\\n");
    final StringBuffer sb = new StringBuffer();
    final StringCharacterIterator iter = new StringCharacterIterator(st);

    for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
        switch (c) {
        case '\t':
            sb.append("\\t");

            break;

        case '\n':
            sb.append("\\n");

            break;

        case '\'':
            sb.append("\\&#39;");

            break;

        case '\"':
            sb.append("\\&quot;");

            break;

        case '&':
            sb.append("&amp;");

            break;

        case '>':
            sb.append("&gt;");

            break;

        case '<':
            sb.append("&lt;");

            break;

        default:
            sb.append(c);

            break;
        }
    }

    return sb.toString();
}

From source file:org.squale.welcom.outils.Util.java

public static String formatEmailList(final String st) {
    final StringBuffer sb = new StringBuffer();
    final StringCharacterIterator iter = new StringCharacterIterator(st);

    for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) {
        if (c != ' ') {
            sb.append(c);//from w  ww . j a  va 2 s  .c  om
        }
    }

    return sb.toString();
}

From source file:org.talend.dataprep.schema.xls.XlsUtils.java

/**
 * return the column number from a cell reference (AA242)
 *
 * @param lastCell/*from   w w  w . j av a  2  s  .  c o m*/
 * @return
 */
public static int getColumnNumberFromCellRef(String lastCell) {

    StringBuilder letters = new StringBuilder();
    // get all letters to remove row number
    StringCharacterIterator iter = new StringCharacterIterator(lastCell);
    for (char c = iter.first(); c != StringCharacterIterator.DONE; c = iter.next()) {
        if (!NumberUtils.isNumber(String.valueOf(c))) {
            letters.append(c);
        }
    }
    // use poi api to calculate column number from an excell column format
    return CellReference.convertColStringToIndex(letters.toString());

}