From e142b4f23ede56a4cb95f2121a4bf56d6896d528 Mon Sep 17 00:00:00 2001 From: Arcterus Date: Fri, 9 Jan 2015 17:20:40 -0800 Subject: [PATCH] env, expand, fmt: fix build --- src/env/env.rs | 1 + src/expand/expand.rs | 2 ++ src/fmt/fmt.rs | 3 +++ src/fmt/linebreak.rs | 16 ++++++++-------- src/fmt/parasplit.rs | 21 ++++++++++++++------- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/env/env.rs b/src/env/env.rs index cc67f1ab4..d2efd5e86 100644 --- a/src/env/env.rs +++ b/src/env/env.rs @@ -12,6 +12,7 @@ /* last synced with: env (GNU coreutils) 8.13 */ #![allow(non_camel_case_types)] +#![feature(box_syntax)] struct options { ignore_env: bool, diff --git a/src/expand/expand.rs b/src/expand/expand.rs index 94ae03e92..716591391 100644 --- a/src/expand/expand.rs +++ b/src/expand/expand.rs @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +#![feature(box_syntax)] + extern crate getopts; extern crate libc; diff --git a/src/fmt/fmt.rs b/src/fmt/fmt.rs index 51673ee0c..0ca41b8d5 100644 --- a/src/fmt/fmt.rs +++ b/src/fmt/fmt.rs @@ -8,8 +8,11 @@ * file that was distributed with this source code. */ +#![feature(box_syntax)] + extern crate core; extern crate getopts; +extern crate unicode; use std::cmp; use std::io::{BufferedReader, BufferedWriter, File, IoResult}; diff --git a/src/fmt/linebreak.rs b/src/fmt/linebreak.rs index 9e1451085..f4d06b44d 100644 --- a/src/fmt/linebreak.rs +++ b/src/fmt/linebreak.rs @@ -94,7 +94,7 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box>>(iter: T, args: &mut BreakArgs<'a>) { +fn break_simple<'a, T: Iterator>>(iter: T, args: &mut BreakArgs<'a>) { iter.fold((args.init_len, false), |l, winfo| accum_words_simple(args, l, winfo)); silent_unwrap!(args.ostream.write_char('\n')); } @@ -120,7 +120,7 @@ fn accum_words_simple<'a>(args: &mut BreakArgs<'a>, (l, prev_punct): (usize, boo // Knuth, D.E., and Plass, M.F. "Breaking Paragraphs into Lines." in Software, // Practice and Experience. Vol. 11, No. 11, November 1981. // http://onlinelibrary.wiley.com/doi/10.1002/spe.4380111102/pdf -fn break_knuth_plass<'a, T: Clone + Iterator<&'a WordInfo<'a>>>(mut iter: T, args: &mut BreakArgs<'a>) { +fn break_knuth_plass<'a, T: Clone + Iterator>>(mut iter: T, args: &mut BreakArgs<'a>) { // run the algorithm to get the breakpoints let breakpoints = find_kp_breakpoints(iter.clone(), args); @@ -183,7 +183,7 @@ struct LineBreak<'a> { fresh : bool } -fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakArgs<'a>) -> Vec<(&'a WordInfo<'a>, bool)> { +fn find_kp_breakpoints<'a, T: Iterator>>(iter: T, args: &BreakArgs<'a>) -> Vec<(&'a WordInfo<'a>, bool)> { let mut iter = iter.peekable(); // set up the initial null linebreak let mut linebreaks = vec!(LineBreak { @@ -199,7 +199,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA let active_breaks = &mut vec!(0); let next_active_breaks = &mut vec!(); - let stretch = (args.opts.width - args.opts.goal) as int; + let stretch = (args.opts.width - args.opts.goal) as isize; let minlength = args.opts.goal - stretch as usize; let mut new_linebreaks = vec!(); let mut is_sentence_start = false; @@ -256,7 +256,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA // there is no penalty for the final line's length (0, 0.0) } else { - compute_demerits((args.opts.goal - tlen) as int, stretch, w.word_nchars as int, active.prev_rat) + compute_demerits((args.opts.goal - tlen) as isize, stretch, w.word_nchars as isize, active.prev_rat) }; // do not even consider adding a line that has too many demerits @@ -344,7 +344,7 @@ const DR_MULT: f32 = 600.0; const DL_MULT: f32 = 300.0; #[inline(always)] -fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (i64, f32) { +fn compute_demerits(delta_len: isize, stretch: isize, wlen: isize, prev_rat: f32) -> (i64, f32) { // how much stretch are we using? let ratio = if delta_len == 0 { @@ -386,8 +386,8 @@ fn restart_active_breaks<'a>(args: &BreakArgs<'a>, active: &LineBreak<'a>, act_i } else { // choose the lesser evil: breaking too early, or breaking too late let wlen = w.word_nchars + args.compute_width(w, active.length, active.fresh); - let underlen: int = (min - active.length) as int; - let overlen: int = ((wlen + slen + active.length) - args.opts.width) as int; + let underlen = (min - active.length) as isize; + let overlen = ((wlen + slen + active.length) - args.opts.width) as isize; if overlen > underlen { // break early, put this word on the next line (true, args.indent_len + w.word_nchars) diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index b36a58ac2..749c160fc 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -11,6 +11,7 @@ use core::iter::Peekable; use std::io::Lines; use std::slice::Iter; use std::str::CharRange; +use unicode::str::UnicodeStr; use FileOrStdReader; use FmtOptions; @@ -78,7 +79,7 @@ impl<'a> FileLines<'a> { // returns true if this line should be formatted fn match_prefix(&self, line: &str) -> (bool, usize) { - if !self.opts.use_prefix { return (true, 0u); } + if !self.opts.use_prefix { return (true, 0); } FileLines::match_prefix_generic(self.opts.prefix.as_slice(), line, self.opts.xprefix) } @@ -100,7 +101,7 @@ impl<'a> FileLines<'a> { if !exact { // we do it this way rather than byte indexing to support unicode whitespace chars - let mut i = 0u; + let mut i = 0; while (i < line.len()) && line.char_at(i).is_whitespace() { i = match line.char_range_at(i) { CharRange { ch: _ , next: nxi } => nxi }; if line.slice_from(i).starts_with(pfx) { @@ -138,7 +139,9 @@ impl<'a> FileLines<'a> { } } -impl<'a> Iterator for FileLines<'a> { +impl<'a> Iterator for FileLines<'a> { + type Item = Line; + fn next(&mut self) -> Option { let n = match self.lines.next() { @@ -252,7 +255,9 @@ impl<'a> ParagraphStream<'a> { } } -impl<'a> Iterator> for ParagraphStream<'a> { +impl<'a> Iterator for ParagraphStream<'a> { + type Item = Result; + fn next(&mut self) -> Option> { // return a NoFormatLine in an Err; it should immediately be output let noformat = @@ -410,7 +415,7 @@ impl<'a> ParaWords<'a> { // no extra spacing for mail headers; always exactly 1 space // safe to trim_left on every line of a mail header, since the // first line is guaranteed not to have any spaces - self.words.extend(self.para.lines.iter().flat_map(|x| x.as_slice().words()).map(|x| WordInfo { + self.words.extend(self.para.lines.iter().flat_map(|x| StrExt::words(x.as_slice())).map(|x| WordInfo { word : x, word_start : 0, word_nchars : x.len(), // OK for mail headers; only ASCII allowed (unicode is escaped) @@ -480,7 +485,7 @@ impl<'a> WordSplit<'a> { impl<'a> WordSplit<'a> { fn new<'b>(opts: &'b FmtOptions, string: &'b str) -> WordSplit<'b> { // wordsplits *must* start at a non-whitespace character - let trim_string = string.trim_left(); + let trim_string = StrExt::trim_left(string); WordSplit { opts: opts, string: trim_string, length: string.len(), position: 0, prev_punct: false } } @@ -504,7 +509,9 @@ pub struct WordInfo<'a> { } // returns (&str, is_start_of_sentence) -impl<'a> Iterator> for WordSplit<'a> { +impl<'a> Iterator for WordSplit<'a> { + type Item = WordInfo<'a>; + fn next(&mut self) -> Option> { if self.position >= self.length { return None