From 1403b35be70d30fccdf68378b3555d1ce74e852b Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Wed, 9 Apr 2014 11:46:49 +1000 Subject: [PATCH] std,syntax: make std::fmt::parse use `Vec`s. --- src/libstd/fmt/parse.rs | 116 ++++++++++++++++++------------------ src/libsyntax/ext/format.rs | 8 +-- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index 4752f3a75f473..36ffb8572378f 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -131,13 +131,13 @@ pub enum Method<'a> { /// /// The final element of this enum is the default "other" case which is /// always required to be specified. - Plural(Option, ~[PluralArm<'a>], ~[Piece<'a>]), + Plural(Option, Vec>, Vec>), /// A select method selects over a string. Each arm is a different string /// which can be selected for. /// /// As with `Plural`, a default "other" case is required as well. - Select(~[SelectArm<'a>], ~[Piece<'a>]), + Select(Vec>, Vec>), } /// A selector for what pluralization a plural method should take @@ -156,7 +156,7 @@ pub struct PluralArm<'a> { /// literal. pub selector: PluralSelector, /// Array of pieces which are the format of this arm - pub result: ~[Piece<'a>], + pub result: Vec>, } /// Enum of the 5 CLDR plural keywords. There is one more, "other", but that @@ -184,7 +184,7 @@ pub struct SelectArm<'a> { /// String selector which guards this arm pub selector: &'a str, /// Array of pieces which are the format of this arm - pub result: ~[Piece<'a>], + pub result: Vec>, } /// The parser structure for interpreting the input format string. This is @@ -198,7 +198,7 @@ pub struct Parser<'a> { cur: str::CharOffsets<'a>, depth: uint, /// Error messages accumulated during parsing - pub errors: ~[~str], + pub errors: Vec<~str>, } impl<'a> Iterator> for Parser<'a> { @@ -236,7 +236,7 @@ impl<'a> Parser<'a> { input: s, cur: s.char_indices(), depth: 0, - errors: ~[], + errors: vec!(), } } @@ -463,7 +463,7 @@ impl<'a> Parser<'a> { /// Parses a 'select' statement (after the initial 'select' word) fn select(&mut self) -> ~Method<'a> { let mut other = None; - let mut arms = ~[]; + let mut arms = vec!(); // Consume arms one at a time loop { self.ws(); @@ -496,7 +496,7 @@ impl<'a> Parser<'a> { Some(arm) => { arm } None => { self.err("`select` statement must provide an `other` case"); - ~[] + vec!() } }; ~Select(arms, other) @@ -506,7 +506,7 @@ impl<'a> Parser<'a> { fn plural(&mut self) -> ~Method<'a> { let mut offset = None; let mut other = None; - let mut arms = ~[]; + let mut arms = vec!(); // First, attempt to parse the 'offset:' field. We know the set of // selector words which can appear in plural arms, and the only ones @@ -594,7 +594,7 @@ impl<'a> Parser<'a> { Some(arm) => { arm } None => { self.err("`plural` statement must provide an `other` case"); - ~[] + vec!() } }; ~Plural(offset, arms, other) @@ -684,9 +684,9 @@ mod tests { use super::*; use prelude::*; - fn same(fmt: &'static str, p: ~[Piece<'static>]) { + fn same(fmt: &'static str, p: &[Piece<'static>]) { let mut parser = Parser::new(fmt); - assert!(p == parser.collect()); + assert!(p == parser.collect::>>().as_slice()); } fn fmtdflt() -> FormatSpec<'static> { @@ -708,12 +708,12 @@ mod tests { #[test] fn simple() { - same("asdf", ~[String("asdf")]); - same("a\\{b", ~[String("a"), String("{b")]); - same("a\\#b", ~[String("a"), String("#b")]); - same("a\\}b", ~[String("a"), String("}b")]); - same("a\\}", ~[String("a"), String("}")]); - same("\\}", ~[String("}")]); + same("asdf", [String("asdf")]); + same("a\\{b", [String("a"), String("{b")]); + same("a\\#b", [String("a"), String("#b")]); + same("a\\}b", [String("a"), String("}b")]); + same("a\\}", [String("a"), String("}")]); + same("\\}", [String("}")]); } #[test] fn invalid01() { musterr("{") } @@ -725,7 +725,7 @@ mod tests { #[test] fn format_nothing() { - same("{}", ~[Argument(Argument { + same("{}", [Argument(Argument { position: ArgumentNext, format: fmtdflt(), method: None, @@ -733,7 +733,7 @@ mod tests { } #[test] fn format_position() { - same("{3}", ~[Argument(Argument { + same("{3}", [Argument(Argument { position: ArgumentIs(3), format: fmtdflt(), method: None, @@ -741,7 +741,7 @@ mod tests { } #[test] fn format_position_nothing_else() { - same("{3:}", ~[Argument(Argument { + same("{3:}", [Argument(Argument { position: ArgumentIs(3), format: fmtdflt(), method: None, @@ -749,7 +749,7 @@ mod tests { } #[test] fn format_type() { - same("{3:a}", ~[Argument(Argument { + same("{3:a}", [Argument(Argument { position: ArgumentIs(3), format: FormatSpec { fill: None, @@ -764,7 +764,7 @@ mod tests { } #[test] fn format_align_fill() { - same("{3:>}", ~[Argument(Argument { + same("{3:>}", [Argument(Argument { position: ArgumentIs(3), format: FormatSpec { fill: None, @@ -776,7 +776,7 @@ mod tests { }, method: None, })]); - same("{3:0<}", ~[Argument(Argument { + same("{3:0<}", [Argument(Argument { position: ArgumentIs(3), format: FormatSpec { fill: Some('0'), @@ -788,7 +788,7 @@ mod tests { }, method: None, })]); - same("{3:* Context<'a, 'b> { } } } - self.verify_pieces(arm.result); + self.verify_pieces(arm.result.as_slice()); } - self.verify_pieces(*default); + self.verify_pieces(default.as_slice()); } parse::Select(ref arms, ref default) => { self.verify_arg_type(pos, String); @@ -258,9 +258,9 @@ impl<'a, 'b> Context<'a, 'b> { self.ecx.span_err(self.fmtsp, "empty selector in `select`"); } - self.verify_pieces(arm.result); + self.verify_pieces(arm.result.as_slice()); } - self.verify_pieces(*default); + self.verify_pieces(default.as_slice()); } } self.nest_level -= 1;