Here you can find the source of searchNewline(CharBuffer buffer, int from)
Parameter | Description |
---|---|
buffer | the character buffer |
from | the position to start searching |
public static int searchNewline(CharBuffer buffer, int from)
//package com.java2s; /*//from w w w . j ava 2s . c o m * Helma License Notice * * The contents of this file are subject to the Helma License * Version 2.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://adele.invoker.org/download/invoker/license.txt * * Copyright 2005 Hannes Wallnoefer. All Rights Reserved. */ import java.nio.CharBuffer; public class Main { /** * Scan for a newline sequence in the given CharBuffer, starting at * position from until buffer.position(). A newline sequence is one of * "r\n", "\r", or "\n". Returns the index of the * first newline sequence, or -1 if none was found. * * @param buffer the character buffer * @param from the position to start searching * @return the index of first newline sequence found, or -1 */ public static int searchNewline(CharBuffer buffer, int from) { int to = buffer.position(); if (from >= to) { return -1; } char[] chars = buffer.array(); for (int i = from; i < to; i++) { if (chars[i] == '\n' || (chars[i] == '\r' && i < to - 1)) { return i; } } return -1; } }