Example usage for java.lang StringBuilder indexOf

List of usage examples for java.lang StringBuilder indexOf

Introduction

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

Prototype

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

Source Link

Usage

From source file:oscar.eform.data.DatabaseAP.java

public static String parserClean(String str) {
    //removes left over ${...} in str; replaces with ""
    StringBuilder strb = new StringBuilder(str);
    int tagstart = -2;
    int tagend;/*from w w w  .  j  ava 2 s .co m*/
    while ((tagstart = strb.indexOf("${", tagstart + 2)) >= 0) {
        strb.replace(tagstart, tagstart + 2, "\"");
        tagend = strb.indexOf("}", tagstart);
        strb.replace(tagend, tagend + 2, "\"");
    }
    return strb.toString();
}

From source file:oscar.eform.data.DatabaseAP.java

public static String parserReplace(String name, String var, String str) {
    //replaces <$name$> with var in str
    StringBuilder strb = new StringBuilder(str);
    int tagstart = -2;
    int tagend;//from   w w  w.j av a 2s  .c  o m
    while ((tagstart = strb.indexOf("${", tagstart + 2)) >= 0) {
        tagend = strb.indexOf("}", tagstart);
        if (strb.substring(tagstart + 2, tagend).equals(name)) {
            strb.replace(tagstart, tagend + 1, var == null ? "" : var);
        }
    }
    return strb.toString();
}

From source file:oscar.eform.data.DatabaseAP.java

public static ArrayList<String> parserGetNames(String str) {
    StringBuilder strb = new StringBuilder(str);
    ArrayList<String> names = new ArrayList<String>();
    int tagstart = -2;
    int tagend;//from w  w  w.j  a  v  a  2s. c o m
    while ((tagstart = strb.indexOf("${", tagstart + 2)) >= 0) {
        tagend = strb.indexOf("}", tagstart);
        names.add(strb.substring(tagstart + 2, tagend));
    }
    return names;
}

From source file:Main.java

public static StringBuilder replaceAll(StringBuilder s, int start, int end, StringBuilder sb, String s1,
        String s2) {//from w  w w .  j a  v a 2s . co  m
    int s1Length = s1.length();
    if (s1Length > 0) {
        int i = start;
        int j;
        while (((j = s.indexOf(s1, i)) >= 0) && j < end) {
            sb.append(s, i, j);
            sb.append(s2);
            i = j + s1Length;
        }
        sb.append(s, i, end);
        return sb;
    } else {
        return sb.append(s);
    }
}

From source file:TextUtils.java

/**
 * Wraps the input string in {@code <html></html>} and breaks it up into
 * lines with {@code <br>} elements. Useful for making multi-line tootips
 * and the like.//from  w  ww.  jav  a 2 s  .  com
 * 
 * @param s
 *            The input String
 * @param lineLength
 *            The desired length of the output lines.
 * @return The HTMLised string
 */
public static String HTMLiseString(String s, int lineLength) {
    if (s != null) {
        StringBuilder buff = new StringBuilder(s);

        int lineStart = 0;

        while (lineStart + lineLength < s.length()) {
            // find the first whitespace after the linelength
            int firstSpaceIndex = buff.indexOf(" ", lineStart + lineLength);
            // replace it with a <br>
            if (firstSpaceIndex != -1) {
                buff.deleteCharAt(firstSpaceIndex);
                buff.insert(firstSpaceIndex, "<br>");
                lineStart = firstSpaceIndex + 4;
            } else {
                lineStart = s.length();
            }
        }

        buff.insert(0, "<html>");
        buff.append("</html>");

        return buff.toString();
    }

    return null;
}

From source file:org.executequery.gui.text.TextUtilities.java

public static void insertLineAfter(JTextComponent textComponent) {
    String newLine = "\n";
    int caretIndex = textComponent.getCaretPosition();

    StringBuilder sb = new StringBuilder(textComponent.getText());

    int endOfLineIndex = sb.indexOf(newLine, caretIndex);

    int length = sb.length();

    if (caretIndex == length || endOfLineIndex == length)
        sb.append(newLine);/*from  w  w  w . ja  va  2s . c  o  m*/
    else
        sb.insert(endOfLineIndex == -1 ? 0 : endOfLineIndex, newLine);

    textComponent.setText(sb.toString());
    textComponent.setCaretPosition(endOfLineIndex == -1 ? length : endOfLineIndex + 1);
    sb = null;
}

From source file:com.ln.methods.Descparser.java

public static void parsedesc() {
    String Desc = "";
    String Title = "";
    String Hour = "";
    String Minute = "";
    String formatted[] = new String[Betaparser.Description.length];
    int selectedindex = Main.Titlebox.getSelectedIndex();
    for (int i1 = 0; i1 != Betaparser.Hours.length; i1++) {
        if (Betaparser.Events[i1].startsWith(Main.monthday)) {
            Desc = Desc + "" + Betaparser.Description[i1] + "~";
            Title = Title + "" + Betaparser.Title[i1] + "~";
            Hour = Hour + "" + Betaparser.Hours[i1] + "~";
            Minute = Minute + "" + Betaparser.Minutes[i1] + "~";
        }/*from w w  w .  jav  a2 s. c o  m*/
    }
    String[] Desc2 = StringUtils.substringsBetween(Desc, "", "~");
    String[] Title2 = StringUtils.substringsBetween(Title, "", "~");
    String[] Hour2 = StringUtils.substringsBetween(Hour, "", "~");
    String[] Minute2 = StringUtils.substringsBetween(Minute, "", "~");
    String[] Full = new String[Desc2.length];
    TTT = "";
    DDD = 0;
    HHH = 0;
    MMM = 0;
    for (int i = 0; i != Title2.length; i++) {
        int h = Integer.parseInt(Hour2[i]);
        int m = Integer.parseInt(Minute2[i]);
        DateFormat df = new SimpleDateFormat("dd");
        DateFormat dm = new SimpleDateFormat("MM");
        Date month = new Date();
        Date today = new Date();
        int mon = Integer.parseInt(dm.format(month));
        int d = Integer.parseInt(df.format(today));
        int dif = 0;
        int ds = 0;
        int pastd = 0;
        int pasth = 0;
        int pastm = 0;
        d = Main.sdate - d;
        h = h - Parser.hour;
        m = m - Parser.minute;
        if (d > 0) {
            ds = 1;
        }
        if (mon > Main.globmonth) {
            dif = dif + 1;
        }
        if (Main.sdate > d) {
            dif = dif + 1;
        }
        if (h < 0) {
            pasth = Math.abs(h);
        }
        if (m < 0) {
            pastm = Math.abs(m);
            h = h - 1;
            m = m + 60;
        }
        if (d < 0) {
            pastd = d;
        }
        if (d > 0 && h < 0) {
            d = d - 1;
            h = h + 24;
        }
        if (d == 0) {
            formatted[i] = "<font size=\"4\" color=\"lime\"><br><b>Starts in: "
                    + String.format("%01d Hours %01d Minutes", h, m) + "</b></font>";
        }
        if (d >= 1) {
            formatted[i] = "<font size=\"4\" color=\"lime\"><br><b>Starts in: "
                    + String.format("%01d Days %01d Hours %01d Minutes", d, h, m) + "</b></font>";
        }
        if (pastd == 0 && h < 0) {
            formatted[i] = "<font size=\"4\" color=\"#B00000\"><br><b>Event is finished/going on. Started "
                    + String.format("%01d Hours %01d Minutes", pasth, pastm) + " Ago</b></font>";
        }
        if (pastd < 0 && h < 0) {
            formatted[i] = "<font size=\"4\" color=\"#B00000\"><br><b>Event is finished/going on. Started "
                    + String.format("%01d Days %01d Hours %01d Minutes", pastd, pasth, pastm)
                    + " Ago</b></font>";
        }

    }

    for (int i = 0; i != Title2.length; i++) {
        Full[i] = Title2[i];

    }

    try {
        if (Desc2[selectedindex] != null) {
            StringBuilder sb = new StringBuilder(Desc2[selectedindex]);
            int i = 0;
            while ((i = sb.indexOf(" ", i + 50)) != -1) {
                //   sb.replace(i, i + 1, "<br>");
                String formatteddesc = sb.toString();
                formatteddesc = formatteddesc.replace("/forum/", "http://www.teamliquid.net/forum/");
                TextProcessor processor = BBProcessorFactory.getInstance().create();
                formatteddesc = processor.process(formatteddesc);
                formatteddesc = formatteddesc.replace("#T#", "").replace("#P#", "").replace("#Z#", "");
                formatteddesc = formatteddesc.replace("[tlpd#players", "[tlpd][cat]players[/cat]");
                formatteddesc = formatteddesc.replace("[/cat]#", "[ID]");
                formatteddesc = formatteddesc.replace("sc2-korean]", "[/ID][region]sc2-korean[/region][name]")
                        .replace("sc2-international", "[/ID][region]sc2-international[/region][name]");
                formatteddesc = formatteddesc.replace("[/tlpd]", "[/name][/tlpd]");
                String[] tlpd = StringUtils.substringsBetween(formatteddesc, "[tlpd]", "[/tlpd]");
                String[] cat = StringUtils.substringsBetween(formatteddesc, "[cat]", "[ID]");
                String[] ids = StringUtils.substringsBetween(formatteddesc, "[ID]", "[/ID]");
                String[] names = StringUtils.substringsBetween(formatteddesc, "[name]", "[/name]");
                String[] region = StringUtils.substringsBetween(formatteddesc, "[region]", "[/region]");

                try {
                    if (formatteddesc.contains("tlpd")) {
                        formatteddesc = formatteddesc.replace("[tlpd]", "").replace("[/tlpd]", "");
                        for (int i1 = 0; i1 != tlpd.length; i1++) {
                            formatteddesc = formatteddesc.replace(tlpd[i1],
                                    "<a href=\"http://www.teamliquid.net/tlpd/" + cat[i1] + "/" + region[i1]
                                            + "/" + ids[i1] + "\">" + names[i1] + "</a>");

                            //   formatteddesc = formatteddesc.replace("[tlpd]", "").replace("[/tlpd]", "");      
                        }
                    }

                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
                formatteddesc = formatteddesc.replace("&lt;", "").replace("gt;", "");
                Main.Description
                        .setText((Full[selectedindex] + formatted[selectedindex] + "<br>" + formatteddesc));
                try {
                    if (formatted[selectedindex].contains("lime")) {
                        String[] notfytime = new String[formatted.length];
                        String[] form = new String[formatted.length];
                        form[selectedindex] = formatted[selectedindex].replace("Starts in: ", "$");
                        notfytime[selectedindex] = StringUtils.substringBetween(form[selectedindex], "$",
                                "</b>");
                        if (formatted[selectedindex].contains("Days")) {
                            String DD = StringUtils.substringBetween(notfytime[selectedindex], "", " Days");
                            String HH = StringUtils.substringBetween(notfytime[selectedindex], "Days ",
                                    " Hours");
                            String MM = StringUtils.substringBetween(notfytime[selectedindex], "Hours ",
                                    " Minutes");
                            DDD = Integer.parseInt(DD);
                            HHH = Integer.parseInt(HH);
                            MMM = Integer.parseInt(MM);
                            TTT = Full[selectedindex];
                        }
                        if (!formatted[selectedindex].contains("Days")) {
                            String HH = StringUtils.substringBetween(notfytime[selectedindex], "", " Hours");
                            String MM = StringUtils.substringBetween(notfytime[selectedindex], "Hours ",
                                    " Minutes");
                            HHH = Integer.parseInt(HH);
                            MMM = Integer.parseInt(MM);
                            TTT = Full[selectedindex];
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Main.Description.setCaretPosition(0);

            }
        }

    } catch (IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

}

From source file:org.executequery.gui.text.TextUtilities.java

public static void deleteWord(JTextComponent textComponent) {
    char space = ' ';
    String _space = " ";
    int caretIndex = textComponent.getCaretPosition();

    String text = textComponent.getText();
    StringBuilder sb = new StringBuilder(text);

    int startOfWordIndex = -1;
    int endOfWordIndex = sb.indexOf(_space, caretIndex);

    char[] textChars = text.toCharArray();

    for (int i = 0; i < textChars.length; i++) {

        if (i >= caretIndex) {
            break;
        }/* w  w w . ja va2 s.  c  o m*/

        else {

            if (textChars[i] == space)
                startOfWordIndex = i;

        }

    }

    if (endOfWordIndex == -1)
        return;

    else if (startOfWordIndex == 0 && endOfWordIndex == 0)
        return;

    else if (startOfWordIndex == endOfWordIndex)
        return;

    sb.delete(startOfWordIndex + 1, endOfWordIndex);
    textComponent.setText(sb.toString());
    textComponent.setCaretPosition(startOfWordIndex + 1);
}

From source file:org.executequery.gui.text.TextUtilities.java

public static void deleteLine(JTextComponent textComponent) {
    char newLine = '\n';
    String _newLine = "\n";
    int caretIndex = textComponent.getCaretPosition();

    String text = textComponent.getText();
    StringBuilder sb = new StringBuilder(text);

    int endOfLineIndexBefore = -1;
    int endOfLineIndexAfter = sb.indexOf(_newLine, caretIndex);

    char[] textChars = text.toCharArray();

    for (int i = 0; i < textChars.length; i++) {

        if (i >= caretIndex) {
            break;
        } else {/*from www .jav a 2  s.  com*/

            if (textChars[i] == newLine)
                endOfLineIndexBefore = i;

        }

    }

    if (endOfLineIndexBefore == -1) {
        endOfLineIndexBefore = 0;
    }

    if (endOfLineIndexAfter == -1) {
        sb.delete(endOfLineIndexBefore, sb.length());
    } else if (endOfLineIndexBefore == -1) {
        sb.delete(0, endOfLineIndexAfter + 1);
    } else if (endOfLineIndexBefore == 0 && endOfLineIndexAfter == 0) {
        sb.deleteCharAt(0);
    } else {
        sb.delete(endOfLineIndexBefore, endOfLineIndexAfter);
    }

    textComponent.setText(sb.toString());

    if (endOfLineIndexBefore + 1 > sb.length()) {

        textComponent.setCaretPosition(endOfLineIndexBefore == -1 ? 0 : endOfLineIndexBefore);

    } else {

        textComponent.setCaretPosition(endOfLineIndexBefore + 1);
    }

}

From source file:org.apache.ofbiz.base.util.UtilIO.java

private static StringBuilder filterLineEndings(StringBuilder sb) {
    String nl = System.getProperty("line.separator");
    if (!nl.equals("\n")) {
        int r = 0;
        while (r < sb.length()) {
            int i = sb.indexOf(nl, r);
            if (i == -1) {
                break;
            }//from ww w . jav  a2s.  com
            sb.replace(i, i + nl.length(), "\n");
            r = i + 1;
        }
    }
    return sb;
}