List of usage examples for org.apache.commons.lang StringUtils indexOfAnyBut
public static int indexOfAnyBut(String str, String searchChars)
Search a String to find the first index of any character not in the given set of characters.
From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java
/** * @return the index of first non-whitespace character or start of first line that is empty or * contains only end of line comments (EOLC). *//*from ww w.ja v a2 s . c o m*/ public int skipWhitespaceAndPureEOLCToLeft(int end) throws Exception { // skip whitespace to the left int index = end - getWhitespaceToLeft(end, false).length(); if (index == 0) { return index; } // skip lines with pure EOLC while (true) { int line = m_document.getLineOfOffset(index - 1); int lineOffset = m_document.getLineOffset(line); String lineString = getSource(lineOffset, m_document.getLineLength(line)); int firstNonWhitespace = StringUtils.indexOfAnyBut(lineString, " \t\r\n"); // check for empty line if (firstNonWhitespace == -1) { index = lineOffset; continue; } // check if line starts with EOLC, so contains only it if (lineString.substring(firstNonWhitespace).startsWith("//")) { index = lineOffset; continue; } // previous line was last empty one break; } // return index; }
From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java
/** * @return single source {@link String} for given lines of source. * // w w w .ja v a 2 s .co m * @param lines * the lines of source * @param indent * the "base" indentation * @param singleIndent * the indentation that to replace each leading "\t" * @param eol * the EOL string */ private static String getIndentedSource(List<String> lines, String indent, String singleIndent, String eol) { StringBuffer buffer = new StringBuffer(); for (String line : lines) { // EOL if (buffer.length() != 0) { buffer.append(eol); } // indentation buffer.append(indent); // line if (line.length() != 0) { int tabsCount = StringUtils.indexOfAnyBut(line, "\t"); if (tabsCount != -1) { buffer.append(StringUtils.repeat(singleIndent, tabsCount)); buffer.append(line.substring(tabsCount)); } else { buffer.append(StringUtils.repeat(singleIndent, line.length())); } } } return buffer.toString(); }
From source file:org.eclipse.wb.internal.core.utils.ast.AstEditor.java
/** * Re-indents source at place./*from w w w . j a v a 2 s . c o m*/ */ private void reindentSource(int sourceStart, int sourceLength, String indent, String eol) throws Exception { // prepare lines String[] lines; { String source = getSource(sourceStart, sourceLength); lines = StringUtils.splitByWholeSeparatorPreserveAllTokens(source, eol); } // change indentation for lines int position = sourceStart; String oldIndent = null; for (String line : lines) { // prepare line indentation String lineIndent = ""; { int endOfIndent = StringUtils.indexOfAnyBut(line, "\t "); if (endOfIndent != -1) { lineIndent = line.substring(0, endOfIndent); } else { lineIndent = line; } } // use indentation of first line as base if (oldIndent == null) { oldIndent = lineIndent; } // replace indentation if (lineIndent.startsWith(oldIndent)) { replaceSubstring(position, oldIndent.length(), indent); position += indent.length() - oldIndent.length(); } // move position to next line position += line.length() + eol.length(); } }
From source file:org.eclipse.wb.internal.swing.model.property.editor.models.tree.TreeModelDialog.java
/** * @return the newly create {@link TreeItem} with given text/indentation. *//* w w w. j a v a 2s. c o m*/ private ItemInformationImpl createItem(TreeItem parent, int parentLevel, String line) { int level = StringUtils.indexOfAnyBut(line, "\t"); if (level == -1) { level = line.length(); } // update parent if (parent == null) { level = 0; } else { // create empty items for (int i = parentLevel; i < level - 1; i++) { parent = new TreeItem(parent, SWT.NONE); parent.setText("(empty)"); parent.setImage(IMAGE_FOLDER); } // go up, if needed for (int i = level - 1; i < parentLevel; i++) { parent = parent.getParentItem(); } } // create new item TreeItem item; if (parent == null) { item = new TreeItem(m_treeWidget, SWT.NONE); } else { parent.setImage(IMAGE_FOLDER); item = new TreeItem(parent, SWT.NONE); } item.setText(line.substring(level)); item.setImage(IMAGE_LEAF); return new ItemInformationImpl(item, level); }
From source file:org.jamwiki.parser.jflex.JFlexLexer.java
/** * Take Wiki text of the form "|" or "| style='foo' |" and convert to * and HTML <td> or <th> tag. * * @param text The text to be parsed.//from w ww . j a v a 2s .co m * @param tagType The HTML tag type, either "td" or "th". * @param markup The Wiki markup for the tag, either "|", "|+" or "!" */ protected void parseTableCell(String text, String tagType, String markup) { if (text == null) { throw new IllegalArgumentException("No text specified while parsing table cell"); } text = text.trim(); String tagAttributes = null; int pos = StringUtils.indexOfAnyBut(text, markup); if (pos != -1) { text = text.substring(pos); pos = text.indexOf('|'); if (pos != -1) { text = text.substring(0, pos); } tagAttributes = JFlexParserUtil.validateHtmlTagAttributes(text.trim()); } this.pushTag(tagType, tagAttributes); }
From source file:org.terrier.utility.UnitUtils.java
public static long parseLong(String str) { if (str == null) throw new NullPointerException(); int notNumberIndex = StringUtils.indexOfAnyBut(str, "0123456789"); if (notNumberIndex == -1) return Long.parseLong(str); long ret = Long.parseLong(str.substring(0, notNumberIndex)); switch (str.substring(notNumberIndex).trim()) { case "G": return ret * G_FACTOR; case "M": return ret * M_FACTOR; case "K": return ret * K_FACTOR; case "Gi": return ret * Gi_FACTOR; case "Mi": return ret * Mi_FACTOR; case "Ki": return ret * Ki_FACTOR; }/* w w w .j a v a 2 s .c o m*/ throw new NumberFormatException(str + " can't be correctly parsed."); }
From source file:org.terrier.utility.UnitUtils.java
public static int parseInt(String str) { if (str == null) throw new NullPointerException(); final int notNumberIndex = StringUtils.indexOfAnyBut(str, "0123456789"); if (notNumberIndex == -1) return Integer.parseInt(str); int ret = Integer.parseInt(str.substring(0, notNumberIndex)); switch (str.substring(notNumberIndex).trim()) { case "G": return (int) (ret * G_FACTOR); case "M": return (int) (ret * M_FACTOR); case "K": return (int) (ret * K_FACTOR); case "Gi": return (int) (ret * Gi_FACTOR); case "Mi": return (int) (ret * Mi_FACTOR); case "Ki": return (int) (ret * Ki_FACTOR); }/*from w w w .j a va 2s. c o m*/ throw new NumberFormatException(str + " can't be correctly parsed."); }
From source file:org.terrier.utility.UnitUtils.java
public static float parseFloat(String str) { if (str == null) throw new NullPointerException(); int notNumberIndex = StringUtils.indexOfAnyBut(str, "0123456789"); if (notNumberIndex == -1) return Float.parseFloat(str); float ret = Float.parseFloat(str.substring(0, notNumberIndex)); switch (str.substring(notNumberIndex).trim()) { case "G": return ret * G_FACTOR; case "M": return ret * M_FACTOR; case "K": return ret * K_FACTOR; case "Gi": return ret * Gi_FACTOR; case "Mi": return ret * Mi_FACTOR; case "Ki": return ret * Ki_FACTOR; }//from ww w . j ava2s . com throw new NumberFormatException(str + " can't be correctly parsed."); }
From source file:org.terrier.utility.UnitUtils.java
public static double parseDouble(String str) { if (str == null) throw new NullPointerException(); int notNumberIndex = StringUtils.indexOfAnyBut(str, "0123456789"); if (notNumberIndex == -1) return Double.parseDouble(str); double ret = Double.parseDouble(str.substring(0, notNumberIndex)); switch (str.substring(notNumberIndex).trim()) { case "G": return ret * G_FACTOR; case "M": return ret * M_FACTOR; case "K": return ret * K_FACTOR; case "Gi": return ret * Gi_FACTOR; case "Mi": return ret * Mi_FACTOR; case "Ki": return ret * Ki_FACTOR; }/*from w ww.j a v a2s.c o m*/ throw new NumberFormatException(str + " can't be correctly parsed."); }