/** * Counts the number of lines where {@link #separator} is assumed to be a valid line break. */ public static int countLines(String text) { return countLines(text, separator); }
/** * Counts the number of lines where {@link #separator} is assumed to be the only valid line break sequence. * A string without any line separators returns {@code 0} as the number of lines. */ public static int countLines(String text) { return countLines(text, separator); }
/** * Counts the number of lines where the given separator sequence is the only valid line break sequence. * A string without any line separators returns {@code 0} as the number of lines. */ public static int countLines(String text, char[] separator) { return countLines(text, separator, 0, text.length()); }
/** * @since 2.0 */ protected int basicGetLineOfOffset(INode rootNode, int offset) { if (rootNode instanceof RootNode) { int[] lineBreakOffsets = ((RootNode) rootNode).basicGetLineBreakOffsets(); int insertionPoint = Arrays.binarySearch(lineBreakOffsets, offset); if (insertionPoint >= 0) { return insertionPoint + 1; } else { return -insertionPoint; } } String leadingText = rootNode.getText().substring(0, offset); int result = Strings.countLines(leadingText); return result + 1; }
if (parserNode != null) { String completeText = parserNode.getRootNode().getText(); int startLine = Strings.countLines(completeText.substring(0, castedDiagnostic.getOffset())) + 1; result.lineNumber = startLine;