<commit_before>/*!
Provides a way to read lines from an unbuffered reader without needing to either push back or buffer bytes.
*/

use std::io::{IoError, IoResult, OtherIoError};

/**
Reads a line of input from the given `Reader`.  This does not require a push back buffer.  It returns the line *with* the line terminator.

Note that this function *does not* support old-school Mac OS newlines (i.e. a single carriage return).  If it encounters a carriage return which is *not* immediately followed by a line feed, the carriage return will be included as part of the line.
*/
pub fn read_line<R: Reader>(r: &mut R) -> IoResult<String> {
	let mut line = String::new();
	loop {
		match try!(read_utf8_char(r)) {
			'\n' => {
				line.push('\n');
				break;
			},
			c => {
				line.push(c);
			}
		}
	}
	Ok(line)
}

#[test]
fn test_read_line() {
	let s = "line one\nline two\r\nline three\n";
	let mut r = ::std::io::BufReader::new(s.as_bytes());
	let oks = |s:&str| Ok(s.into_string());

	assert_eq!(read_line(&mut r), oks("line one\n"));
	assert_eq!(read_line(&mut r), oks("line two\r\n"));
	assert_eq!(read_line(&mut r), oks("line three\n"));
}<commit_msg>Changed io::read_line to *not* error on incomplete lines.<commit_after>/*!
Provides a way to read lines from an unbuffered reader without needing to either push back or buffer bytes.
*/

use std::io::{IoError, IoResult, OtherIoError};

/**
Reads a line of input from the given `Reader`.  This does not require a push back buffer.  It returns the line *with* the line terminator.

Note that this function *does not* support old-school Mac OS newlines (i.e. a single carriage return).  If it encounters a carriage return which is *not* immediately followed by a line feed, the carriage return will be included as part of the line.
*/
pub fn read_line<R: Reader>(r: &mut R) -> IoResult<String> {
	let mut line = String::new();
	loop {
		match read_utf8_char(r) {
			Ok('\n') => {
				line.push('\n');
				break;
			},
			Ok(c) => {
				line.push(c);
			}
			Err(err) => {
				if err.kind == ::std::io::EndOfFile && line.len() > 0 {
					break
				} else {
					return Err(err)
				}
			}
		}
	}
	Ok(line)
}

#[test]
fn test_read_line() {
	let s = "line one\nline two\r\nline three\n";
	let mut r = ::std::io::BufReader::new(s.as_bytes());
	let oks = |s:&str| Ok(s.into_string());

	assert_eq!(read_line(&mut r), oks("line one\n"));
	assert_eq!(read_line(&mut r), oks("line two\r\n"));
	assert_eq!(read_line(&mut r), oks("line three\n"));
}
{'fraction_non_alphanumeric': 0.1552346570397112, 'fraction_numerical': 0.0012033694344163659, 'mean_word_length': 3.7145557655954633, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5669472', 'n_tokens_mistral': 937, 'n_tokens_neox': 871, 'n_words': 297}