Example usage for java.lang StringBuffer indexOf

List of usage examples for java.lang StringBuffer indexOf

Introduction

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

Prototype

@Override
public synchronized int indexOf(String str, int fromIndex) 

Source Link

Usage

From source file:Main.java

public static void main(String[] arg) {

    StringBuffer buffer = new StringBuffer("from java2s.com");

    System.out.println(buffer.indexOf("ava", 2));
}

From source file:Main.java

private static String removeSingleQuotes(StringBuffer tempBuffer, int questionSignIndex) {
    int delRightIndex = tempBuffer.indexOf("'", questionSignIndex);
    int delLeftIndex = tempBuffer.lastIndexOf("'", questionSignIndex);

    if (isDelSingleQuotes(tempBuffer, delLeftIndex, delRightIndex)) {
        tempBuffer.deleteCharAt(delRightIndex);
        tempBuffer.deleteCharAt(delLeftIndex);
    }/*from w w w. j  ava2s  .c o m*/
    return tempBuffer.toString();
}

From source file:Main.java

/**
 * Return true if the string starting at offset in sb matches with xmlTag.
 * @param sb StringBuffer/*w w  w  .  j a  v  a  2  s. c  om*/
 * @param offset int
 * @param xmlTag String The XML tag name to check without '<' and '>'
 * @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:misc.TestUtils.java

private static final String removeHashCodes(String toStringValue) {
    StringBuffer sb = new StringBuffer(toStringValue);
    for (int monkeyInd = 0; monkeyInd < sb.length();) {
        int ind = sb.indexOf("@", monkeyInd + 1);
        if (ind == -1)
            break;
        int ind2 = sb.indexOf("[", ind + 1);
        sb.delete(ind, ind2);//from  w w  w.ja va  2s .  com
    }
    return sb.toString();
}

From source file:org.eclipse.rwt.widgets.codemirror.internal.CodeMirrorJSService.java

/**
 * Builds a url which points to the service handler and encodes the given parameters
 * as url parameters. //from  w ww  . j  a v a2  s . c  o  m
 */
public static String getBaseUrl() {
    StringBuffer url = new StringBuffer();
    url.append(URLHelper.getURLString(false));

    URLHelper.appendFirstParam(url, REQUEST_PARAM, SERVICE_HANDLER_ID);

    // convert to relative URL
    int firstSlash = url.indexOf("/", url.indexOf("//") + 2); // first slash after double slash of "http://"
    url.delete(0, firstSlash + 1); // Result is sth like "/rap?custom_service_handler..."
    return RWT.getResponse().encodeURL(url.toString());
}

From source file:com.silverpeas.ical.StringUtils.java

private static long resolveUnit(StringBuffer buffer) {
    long unit = 1;
    int i = -1;//  w  w w. j av a2  s.com
    for (;;) {
        i = buffer.indexOf("msec", 0);
        if (i != -1) {
            break;
        }
        i = buffer.indexOf("mill", 0);
        if (i != -1) {
            break;
        }
        i = buffer.indexOf("sec", 0);
        if (i != -1) {
            unit = 1000L;
            break;
        }
        i = buffer.indexOf("min", 0);
        if (i != -1) {
            unit = 1000L * 60;
            break;
        }
        i = buffer.indexOf("hour", 0);
        if (i != -1) {
            unit = 1000L * 60 * 60;
            break;
        }
        i = buffer.indexOf("day", 0);
        if (i != -1) {
            unit = 1000L * 60 * 60 * 24;
            break;
        }
        i = buffer.indexOf("week", 0);
        if (i != -1) {
            unit = 1000L * 60 * 60 * 24 * 7;
            break;
        }
        i = buffer.indexOf("month", 0);
        if (i != -1) {
            unit = 1000L * 60 * 60 * 24 * 30;
            break;
        }
        i = buffer.indexOf("year", 0);
        if (i != -1) {
            unit = 1000L * 60 * 60 * 24 * 365;
            break;
        }
        i = buffer.indexOf("kbyte", 0);
        if (i != -1) {
            unit = 1024L;
            break;
        }
        i = buffer.indexOf("mbyte", 0);
        if (i != -1) {
            unit = 1024L * 1024;
            break;
        }
        i = buffer.indexOf("gbyte", 0);
        if (i != -1) {
            unit = 1024L * 1024 * 1024;
            break;
        }
        i = buffer.indexOf("tbyte", 0);
        if (i != -1) {
            unit = 1024L * 1024 * 1024 * 1024;
            break;
        }
        i = buffer.indexOf("byte", 0);
        break;
    }
    if (i != -1) {
        buffer.setLength(i);
    }
    return unit;
}

From source file:org.dbgl.util.searchengine.WebSearchEngine.java

protected static String removeTag(final String openTag, final String closeTag, final String htmlChunk) {
    StringBuffer result = new StringBuffer(htmlChunk);
    int openingIndex = StringUtils.indexOfIgnoreCase(result, openTag);
    while (openingIndex != -1) {
        result.delete(openingIndex, result.indexOf(">", openingIndex + openTag.length()) + 1);
        int closingIndex = StringUtils.indexOfIgnoreCase(result, closeTag);
        result.delete(closingIndex, closingIndex + closeTag.length());
        openingIndex = StringUtils.indexOfIgnoreCase(result, openTag);
    }//from  w w w.  j av  a2s .  co m
    return result.toString();
}

From source file:org.polymap.core.data.operation.DownloadServiceHandler.java

/**
 * Registers the given provider for downloading.
 * /*from   www .  j  a v a  2 s . c  o m*/
 * @param id
 * @param provider
 * @return The download URL for the given provider.
 */
public static String registerContent(String id, ContentProvider provider) {
    if (providers.put(id, provider) != null) {
        log.warn("ContetProvider already registered for id: " + id);
    }

    // XXX code from RAP; its a bit confusing, don't like it but it works
    StringBuffer url = new StringBuffer(256);
    url.append(URLHelper.getURLString(false));

    URLHelper.appendFirstParam(url, REQUEST_PARAM, SERVICE_HANDLER_ID);
    URLHelper.appendParam(url, ID_REQUEST_PARAM, id);

    // convert to relative URL
    int firstSlash = url.indexOf("/", url.indexOf("//") + 2); // first slash after double slash of "http://"
    url.delete(0, firstSlash + 1); // Result is sth like "/rap?custom_service_handler..."
    return RWT.getResponse().encodeURL(url.toString());
}

From source file:org.codehaus.groovy.grails.plugins.searchable.util.StringQueryUtils.java

/**
 * Highlights the different terms in the second query and returns a new query string.
 * This method is intended to be used with suggested queries to display the suggestion
 * to the user in highlighted format, as per Google, so the queries are expected to roughly match
 * @param first the original query//www  . j a v  a 2 s . c om
 * @param second the second query, in which to highlight differences
 * @param highlightPattern the pattern used to highlight; should be a {@link MessageFormat} pattern where argument
 * zero is the highlighted term text
 * @return a new copy of second with term differences highlighted
 * @throws ParseException if either first or second query is invalid
 * @see #highlightTermDiffs(String, String)
 */
public static String highlightTermDiffs(String first, String second, String highlightPattern)
        throws ParseException {
    final String defaultField = "$StringQueryUtils_highlightTermDiffs$";
    Term[] firstTerms = LuceneUtils.realTermsForQueryString(defaultField, first, WhitespaceAnalyzer.class);
    Term[] secondTerms = LuceneUtils.realTermsForQueryString(defaultField, second, WhitespaceAnalyzer.class);

    if (firstTerms.length != secondTerms.length) {
        LOG.warn("Expected the same number of terms for first query [" + first + "] and second query [" + second
                + "], " + "but first query has [" + firstTerms.length + "] terms and second query has ["
                + secondTerms.length + "] terms "
                + "so unable to provide user friendly version. Returning second query as-is.");
        return second;
    }

    MessageFormat format = new MessageFormat(highlightPattern);
    StringBuffer diff = new StringBuffer(second);
    int offset = 0;
    for (int i = 0; i < secondTerms.length; i++) {
        Term firstTerm = firstTerms[i];
        Term secondTerm = secondTerms[i];
        boolean noField = defaultField.equals(secondTerm.field());
        String snippet = noField ? secondTerm.text() : secondTerm.field() + ":" + secondTerm.text();
        int pos = diff.indexOf(snippet, offset);
        if (!firstTerm.text().equals(secondTerm.text())) {
            if (!noField) {
                pos += secondTerm.field().length() + 1;
            }
            diff.replace(pos, pos + secondTerm.text().length(),
                    format.format(new Object[] { secondTerm.text() }));
        }
        offset = pos;
    }
    return diff.toString();
}

From source file:org.eclipse.rwt.widgets.upload.servlet.FileUploadServiceHandler.java

/**
 * Builds a url which points to the service handler and encodes the given parameters
 * as url parameters. //from   www  .  j av a2s  .c o m
 */
public static String getUrl(final String widgetId) {
    StringBuffer url = new StringBuffer();
    url.append(URLHelper.getURLString(false));

    URLHelper.appendFirstParam(url, REQUEST_PARAM, getServiceHandlerId());
    URLHelper.appendParam(url, REQUEST_WIDGET_ID, widgetId);

    // convert to relative URL
    int firstSlash = url.indexOf("/", url.indexOf("//") + 2); // first slash after double slash of "http://"
    url.delete(0, firstSlash + 1); // Result is sth like "/rap?custom_service_handler..."
    return RWT.getResponse().encodeURL(url.toString());
}