List of usage examples for org.apache.commons.lang StringUtils indexOf
public static int indexOf(String str, String searchStr, int startPos)
Finds the first index within a String, handling null
.
From source file:org.sonar.ide.eclipse.internal.ui.jobs.AbstractRefreshModelJob.java
private void addLine(final Map<String, Object> markerAttributes, final long line, final String text) { int start = 0; for (int i = 1; i < line; i++) { start = StringUtils.indexOf(text, '\n', start) + 1; }//from w w w .java 2 s.c om final int end = StringUtils.indexOf(text, '\n', start); markerAttributes.put(IMarker.CHAR_START, start); markerAttributes.put(IMarker.CHAR_END, end); }
From source file:org.sonar.plugins.web.checks.coding.MaxLineLengthCheck.java
private void handleNode(Node node) { currentNode = node;//from www . j av a 2 s. c o m String code = node.getCode(); int startPos = 0; int indexPos; int newlines = 0; while ((indexPos = StringUtils.indexOf(code, '\n', startPos)) >= 0) { currentLineLength += indexPos - startPos; check(node, newlines); startPos = indexPos + 1; newlines++; } if (startPos < code.length()) { currentLineLength += code.length() - startPos; } }
From source file:pl.otros.logview.gui.message.StackTraceFinder.java
public SortedSet<SubText> findStackTraces(String text) { SortedSet<SubText> set = new TreeSet<SubText>(); LinkedList<Integer> newLineIndexes = new LinkedList<Integer>(); newLineIndexes.add(0);//from w w w . j a v a2s . c om int newLineIndex = -1; while ((newLineIndex = StringUtils.indexOf(text, '\n', newLineIndex + 1)) > -1) { newLineIndexes.addLast(newLineIndex); } if (newLineIndexes.getLast() < text.length()) { newLineIndexes.addLast(text.length()); } int startLine; int endLine; boolean found = false; int startedLineException = -1; for (int i = 0; i < newLineIndexes.size() - 1; i++) { startLine = newLineIndexes.get(i); endLine = newLineIndexes.get(i + 1); String line = text.substring(startLine, endLine); Matcher matcher = exceptionLine.matcher(line); boolean f = matcher.find(); if (f && !found) { startedLineException = i - 1; } else if (!f && found) { // exception end int start = newLineIndexes.get(startedLineException); int end = newLineIndexes.get(i); SubText subText = new SubText(start, end); set.add(subText); } found = f; } // Add stacktrace if string with end of stacktrace if (found) { int start = newLineIndexes.get(startedLineException); int end = newLineIndexes.getLast(); SubText subText = new SubText(start, end); set.add(subText); } // for (SubText subText : set) { // System.out.printf("[%d -> %d] \n\"%s\"", subText.start, subText.end, text.substring(subText.start, subText.end)); // } return set; }