From 0c44dad8cacc95ad6abd39fda5ab9663c3bdccce Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Thu, 7 May 2015 23:06:11 +0200 Subject: =?UTF-8?q?vtcol.rs:=20finally=20catch=20up=20with=201.0;=20lots?= =?UTF-8?q?=20of=20=E2=80=9Cfeature=E2=80=9D=20directives?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/vtcol.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/vtcol.rs b/src/vtcol.rs index 9a865c8..9f0779e 100644 --- a/src/vtcol.rs +++ b/src/vtcol.rs @@ -1,8 +1,13 @@ -#![allow(unstable)] +#![feature(libc)] +#![feature(rustc_private)] +#![feature(collections)] +#![feature(convert)] extern crate libc; extern crate getopts; +use std::io::BufRead; + type Fd = libc::c_int; const PALETTE_SIZE : usize = 16_usize; @@ -397,21 +402,21 @@ impl Palette { { let mut pal_idx : usize = 0_usize; let mut pal : [u8; PALETTE_BYTES] = unsafe { std::mem::zeroed() }; + let mut line : String = String::new(); - while let Ok(line) = reader.read_line() { - let len = line.len(); + while let Ok(len) = reader.read_line(&mut line) { if len < 8_usize { panic!("invalid line in string: {}", line); }; - if let Some(off) = line.find_str("#") { + if let Some(off) = line.find('#') { if off != 0_usize { /* Palette index specified, number prepended */ - let str_idx = line.slice_chars(0, off); - let parse_res : Result + let str_idx = unsafe { line.slice_unchecked(0_usize, off) }; + let parse_res : Result = std::str::FromStr::from_str(str_idx); match parse_res { - Some(new_idx) => { + Ok(new_idx) => { if new_idx < PALETTE_SIZE { pal_idx = new_idx * 3_usize; } }, - None => () + _ => () } } let off = off + 1_usize; @@ -437,7 +442,7 @@ impl Palette { { /* Check if file exists */ - let path = std::path::Path::new(fname.as_bytes()); + let path = std::path::Path::new(fname); let file = match std::fs::File::open(&path) { Err(e) => panic!("failed to open {} as file ({})", fname, e), -- cgit v1.2.3