Skip to content

remove use of "either" in rt.rs and followingly mod.rs #9294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/libstd/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ use char::Char;
use rt::io::Decorator;
use rt::io::mem::MemWriter;
use rt::io;
use fmt::rt::{Keyword, LiteralNumber};
use str;
use sys;
use util;
Expand Down Expand Up @@ -678,7 +679,7 @@ impl<'self> Formatter<'self> {
// offsetted value
for s in selectors.iter() {
match s.selector {
Right(val) if value == val => {
LiteralNumber(val) if value == val => {
return self.runplural(value, s.result);
}
_ => {}
Expand All @@ -690,17 +691,17 @@ impl<'self> Formatter<'self> {
let value = value - match offset { Some(i) => i, None => 0 };
for s in selectors.iter() {
let run = match s.selector {
Left(parse::Zero) => value == 0,
Left(parse::One) => value == 1,
Left(parse::Two) => value == 2,
Keyword(parse::Zero) => value == 0,
Keyword(parse::One) => value == 1,
Keyword(parse::Two) => value == 2,

// XXX: Few/Many should have a user-specified boundary
// One possible option would be in the function
// pointer of the 'arg: Argument' struct.
Left(parse::Few) => value < 8,
Left(parse::Many) => value >= 8,
Keyword(parse::Few) => value < 8,
Keyword(parse::Many) => value >= 8,

Right(*) => false
LiteralNumber(*) => false
};
if run {
return self.runplural(value, s.result);
Expand Down
8 changes: 6 additions & 2 deletions src/libstd/fmt/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#[allow(missing_doc)];
#[doc(hidden)];

use either::Either;
use fmt::parse;
use option::Option;

Expand Down Expand Up @@ -51,8 +50,13 @@ pub enum Method<'self> {
Select(&'self [SelectArm<'self>], &'self [Piece<'self>]),
}

pub enum PluralSelector{
Keyword(parse::PluralKeyword),
LiteralNumber(uint)
}

pub struct PluralArm<'self> {
selector: Either<parse::PluralKeyword, uint>,
selector: PluralSelector,
result: &'self [Piece<'self>],
}

Expand Down