Fix build with rust 1.13.0
This commit is contained in:
parent
a716b48e9d
commit
0b8c248791
|
@ -382,11 +382,11 @@ pub fn format<'a, I, B>(
|
||||||
|
|
||||||
for item in items {
|
for item in items {
|
||||||
match item.borrow() {
|
match item.borrow() {
|
||||||
Item::Literal(s) | Item::Space(s) => result.push_str(s),
|
&Item::Literal(s) | &Item::Space(s) => result.push_str(s),
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
Item::OwnedLiteral(ref s) | Item::OwnedSpace(ref s) => result.push_str(s),
|
&Item::OwnedLiteral(ref s) | &Item::OwnedSpace(ref s) => result.push_str(s),
|
||||||
|
|
||||||
Item::Numeric(spec, pad) => {
|
&Item::Numeric(ref spec, ref pad) => {
|
||||||
use self::Numeric::*;
|
use self::Numeric::*;
|
||||||
|
|
||||||
let week_from_sun = |d: &NaiveDate|
|
let week_from_sun = |d: &NaiveDate|
|
||||||
|
@ -395,31 +395,31 @@ pub fn format<'a, I, B>(
|
||||||
(d.ordinal() as i32 - d.weekday().num_days_from_monday() as i32 + 7) / 7;
|
(d.ordinal() as i32 - d.weekday().num_days_from_monday() as i32 + 7) / 7;
|
||||||
|
|
||||||
let (width, v) = match spec {
|
let (width, v) = match spec {
|
||||||
Year => (4, date.map(|d| i64::from(d.year()))),
|
&Year => (4, date.map(|d| i64::from(d.year()))),
|
||||||
YearDiv100 => (2, date.map(|d| div_floor(i64::from(d.year()), 100))),
|
&YearDiv100 => (2, date.map(|d| div_floor(i64::from(d.year()), 100))),
|
||||||
YearMod100 => (2, date.map(|d| mod_floor(i64::from(d.year()), 100))),
|
&YearMod100 => (2, date.map(|d| mod_floor(i64::from(d.year()), 100))),
|
||||||
IsoYear => (4, date.map(|d| i64::from(d.iso_week().year()))),
|
&IsoYear => (4, date.map(|d| i64::from(d.iso_week().year()))),
|
||||||
IsoYearDiv100 => (2, date.map(|d| div_floor(
|
&IsoYearDiv100 => (2, date.map(|d| div_floor(
|
||||||
i64::from(d.iso_week().year()), 100))),
|
i64::from(d.iso_week().year()), 100))),
|
||||||
IsoYearMod100 => (2, date.map(|d| mod_floor(
|
&IsoYearMod100 => (2, date.map(|d| mod_floor(
|
||||||
i64::from(d.iso_week().year()), 100))),
|
i64::from(d.iso_week().year()), 100))),
|
||||||
Month => (2, date.map(|d| i64::from(d.month()))),
|
&Month => (2, date.map(|d| i64::from(d.month()))),
|
||||||
Day => (2, date.map(|d| i64::from(d.day()))),
|
&Day => (2, date.map(|d| i64::from(d.day()))),
|
||||||
WeekFromSun => (2, date.map(|d| i64::from(week_from_sun(d)))),
|
&WeekFromSun => (2, date.map(|d| i64::from(week_from_sun(d)))),
|
||||||
WeekFromMon => (2, date.map(|d| i64::from(week_from_mon(d)))),
|
&WeekFromMon => (2, date.map(|d| i64::from(week_from_mon(d)))),
|
||||||
IsoWeek => (2, date.map(|d| i64::from(d.iso_week().week()))),
|
&IsoWeek => (2, date.map(|d| i64::from(d.iso_week().week()))),
|
||||||
NumDaysFromSun => (1, date.map(|d| i64::from(d.weekday()
|
&NumDaysFromSun => (1, date.map(|d| i64::from(d.weekday()
|
||||||
.num_days_from_sunday()))),
|
.num_days_from_sunday()))),
|
||||||
WeekdayFromMon => (1, date.map(|d| i64::from(d.weekday()
|
&WeekdayFromMon => (1, date.map(|d| i64::from(d.weekday()
|
||||||
.number_from_monday()))),
|
.number_from_monday()))),
|
||||||
Ordinal => (3, date.map(|d| i64::from(d.ordinal()))),
|
&Ordinal => (3, date.map(|d| i64::from(d.ordinal()))),
|
||||||
Hour => (2, time.map(|t| i64::from(t.hour()))),
|
&Hour => (2, time.map(|t| i64::from(t.hour()))),
|
||||||
Hour12 => (2, time.map(|t| i64::from(t.hour12().1))),
|
&Hour12 => (2, time.map(|t| i64::from(t.hour12().1))),
|
||||||
Minute => (2, time.map(|t| i64::from(t.minute()))),
|
&Minute => (2, time.map(|t| i64::from(t.minute()))),
|
||||||
Second => (2, time.map(|t| i64::from(t.second() +
|
&Second => (2, time.map(|t| i64::from(t.second() +
|
||||||
t.nanosecond() / 1_000_000_000))),
|
t.nanosecond() / 1_000_000_000))),
|
||||||
Nanosecond => (9, time.map(|t| i64::from(t.nanosecond() % 1_000_000_000))),
|
&Nanosecond => (9, time.map(|t| i64::from(t.nanosecond() % 1_000_000_000))),
|
||||||
Timestamp => (1, match (date, time, off) {
|
&Timestamp => (1, match (date, time, off) {
|
||||||
(Some(d), Some(t), None) =>
|
(Some(d), Some(t), None) =>
|
||||||
Some(d.and_time(*t).timestamp()),
|
Some(d.and_time(*t).timestamp()),
|
||||||
(Some(d), Some(t), Some(&(_, off))) =>
|
(Some(d), Some(t), Some(&(_, off))) =>
|
||||||
|
@ -428,24 +428,24 @@ pub fn format<'a, I, B>(
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// for the future expansion
|
// for the future expansion
|
||||||
Internal(ref int) => match int._dummy {},
|
&Internal(ref int) => match int._dummy {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if let Some(v) = v {
|
if let Some(v) = v {
|
||||||
try!(
|
try!(
|
||||||
if (*spec == Year || *spec == IsoYear) && !(0 <= v && v < 10_000) {
|
if (spec == &Year || spec == &IsoYear) && !(0 <= v && v < 10_000) {
|
||||||
// non-four-digit years require an explicit sign as per ISO 8601
|
// non-four-digit years require an explicit sign as per ISO 8601
|
||||||
match pad {
|
match pad {
|
||||||
Pad::None => write!(result, "{:+}", v),
|
&Pad::None => write!(result, "{:+}", v),
|
||||||
Pad::Zero => write!(result, "{:+01$}", v, width + 1),
|
&Pad::Zero => write!(result, "{:+01$}", v, width + 1),
|
||||||
Pad::Space => write!(result, "{:+1$}", v, width + 1),
|
&Pad::Space => write!(result, "{:+1$}", v, width + 1),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match pad {
|
match pad {
|
||||||
Pad::None => write!(result, "{}", v),
|
&Pad::None => write!(result, "{}", v),
|
||||||
Pad::Zero => write!(result, "{:01$}", v, width),
|
&Pad::Zero => write!(result, "{:01$}", v, width),
|
||||||
Pad::Space => write!(result, "{:1$}", v, width),
|
&Pad::Space => write!(result, "{:1$}", v, width),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -454,7 +454,7 @@ pub fn format<'a, I, B>(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Item::Fixed(spec) => {
|
&Item::Fixed(ref spec) => {
|
||||||
use self::Fixed::*;
|
use self::Fixed::*;
|
||||||
|
|
||||||
/// Prints an offset from UTC in the format of `+HHMM` or `+HH:MM`.
|
/// Prints an offset from UTC in the format of `+HHMM` or `+HH:MM`.
|
||||||
|
@ -480,41 +480,41 @@ pub fn format<'a, I, B>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let ret = match spec {
|
let ret = match spec {
|
||||||
ShortMonthName =>
|
&ShortMonthName =>
|
||||||
date.map(|d| {
|
date.map(|d| {
|
||||||
result.push_str(SHORT_MONTHS[d.month0() as usize]);
|
result.push_str(SHORT_MONTHS[d.month0() as usize]);
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
LongMonthName =>
|
&LongMonthName =>
|
||||||
date.map(|d| {
|
date.map(|d| {
|
||||||
result.push_str(LONG_MONTHS[d.month0() as usize]);
|
result.push_str(LONG_MONTHS[d.month0() as usize]);
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
ShortWeekdayName =>
|
&ShortWeekdayName =>
|
||||||
date.map(|d| {
|
date.map(|d| {
|
||||||
result.push_str(
|
result.push_str(
|
||||||
SHORT_WEEKDAYS[d.weekday().num_days_from_monday() as usize]
|
SHORT_WEEKDAYS[d.weekday().num_days_from_monday() as usize]
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
LongWeekdayName =>
|
&LongWeekdayName =>
|
||||||
date.map(|d| {
|
date.map(|d| {
|
||||||
result.push_str(
|
result.push_str(
|
||||||
LONG_WEEKDAYS[d.weekday().num_days_from_monday() as usize]
|
LONG_WEEKDAYS[d.weekday().num_days_from_monday() as usize]
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
LowerAmPm =>
|
&LowerAmPm =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
result.push_str(if t.hour12().0 {"pm"} else {"am"});
|
result.push_str(if t.hour12().0 {"pm"} else {"am"});
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
UpperAmPm =>
|
&UpperAmPm =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
result.push_str(if t.hour12().0 {"PM"} else {"AM"});
|
result.push_str(if t.hour12().0 {"PM"} else {"AM"});
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
Nanosecond =>
|
&Nanosecond =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
if nano == 0 {
|
if nano == 0 {
|
||||||
|
@ -527,52 +527,52 @@ pub fn format<'a, I, B>(
|
||||||
write!(result, ".{:09}", nano)
|
write!(result, ".{:09}", nano)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Nanosecond3 =>
|
&Nanosecond3 =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
write!(result, ".{:03}", nano / 1_000_000)
|
write!(result, ".{:03}", nano / 1_000_000)
|
||||||
}),
|
}),
|
||||||
Nanosecond6 =>
|
&Nanosecond6 =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
write!(result, ".{:06}", nano / 1_000)
|
write!(result, ".{:06}", nano / 1_000)
|
||||||
}),
|
}),
|
||||||
Nanosecond9 =>
|
&Nanosecond9 =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
write!(result, ".{:09}", nano)
|
write!(result, ".{:09}", nano)
|
||||||
}),
|
}),
|
||||||
Internal(InternalFixed { val: InternalInternal::Nanosecond3NoDot }) =>
|
&Internal(InternalFixed { val: InternalInternal::Nanosecond3NoDot }) =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
write!(result, "{:03}", nano / 1_000_000)
|
write!(result, "{:03}", nano / 1_000_000)
|
||||||
}),
|
}),
|
||||||
Internal(InternalFixed { val: InternalInternal::Nanosecond6NoDot }) =>
|
&Internal(InternalFixed { val: InternalInternal::Nanosecond6NoDot }) =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
write!(result, "{:06}", nano / 1_000)
|
write!(result, "{:06}", nano / 1_000)
|
||||||
}),
|
}),
|
||||||
Internal(InternalFixed { val: InternalInternal::Nanosecond9NoDot }) =>
|
&Internal(InternalFixed { val: InternalInternal::Nanosecond9NoDot }) =>
|
||||||
time.map(|t| {
|
time.map(|t| {
|
||||||
let nano = t.nanosecond() % 1_000_000_000;
|
let nano = t.nanosecond() % 1_000_000_000;
|
||||||
write!(result, "{:09}", nano)
|
write!(result, "{:09}", nano)
|
||||||
}),
|
}),
|
||||||
TimezoneName =>
|
&TimezoneName =>
|
||||||
off.map(|&(ref name, _)| {
|
off.map(|&(ref name, _)| {
|
||||||
result.push_str(name);
|
result.push_str(name);
|
||||||
Ok(())
|
Ok(())
|
||||||
}),
|
}),
|
||||||
TimezoneOffsetColon =>
|
&TimezoneOffsetColon =>
|
||||||
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, false, true)),
|
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, false, true)),
|
||||||
TimezoneOffsetColonZ =>
|
&TimezoneOffsetColonZ =>
|
||||||
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, true, true)),
|
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, true, true)),
|
||||||
TimezoneOffset =>
|
&TimezoneOffset =>
|
||||||
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, false, false)),
|
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, false, false)),
|
||||||
TimezoneOffsetZ =>
|
&TimezoneOffsetZ =>
|
||||||
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, true, false)),
|
off.map(|&(_, off)| write_local_minus_utc(&mut result, off, true, false)),
|
||||||
Internal(InternalFixed { val: InternalInternal::TimezoneOffsetPermissive }) =>
|
&Internal(InternalFixed { val: InternalInternal::TimezoneOffsetPermissive }) =>
|
||||||
panic!("Do not try to write %#z it is undefined"),
|
panic!("Do not try to write %#z it is undefined"),
|
||||||
RFC2822 => // same to `%a, %e %b %Y %H:%M:%S %z`
|
&RFC2822 => // same to `%a, %e %b %Y %H:%M:%S %z`
|
||||||
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
|
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
|
||||||
let sec = t.second() + t.nanosecond() / 1_000_000_000;
|
let sec = t.second() + t.nanosecond() / 1_000_000_000;
|
||||||
try!(write!(
|
try!(write!(
|
||||||
|
@ -586,7 +586,7 @@ pub fn format<'a, I, B>(
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
RFC3339 => // same to `%Y-%m-%dT%H:%M:%S%.f%:z`
|
&RFC3339 => // same to `%Y-%m-%dT%H:%M:%S%.f%:z`
|
||||||
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
|
if let (Some(d), Some(t), Some(&(_, off))) = (date, time, off) {
|
||||||
// reuse `Debug` impls which already print ISO 8601 format.
|
// reuse `Debug` impls which already print ISO 8601 format.
|
||||||
// this is faster in this way.
|
// this is faster in this way.
|
||||||
|
@ -603,7 +603,7 @@ pub fn format<'a, I, B>(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
Item::Error => return Err(fmt::Error),
|
&Item::Error => return Err(fmt::Error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -213,56 +213,56 @@ pub fn parse<'a, I, B>(parsed: &mut Parsed, mut s: &str, items: I) -> ParseResul
|
||||||
|
|
||||||
for item in items {
|
for item in items {
|
||||||
match item.borrow() {
|
match item.borrow() {
|
||||||
Item::Literal(prefix) => {
|
&Item::Literal(prefix) => {
|
||||||
if s.len() < prefix.len() { return Err(TOO_SHORT); }
|
if s.len() < prefix.len() { return Err(TOO_SHORT); }
|
||||||
if !s.starts_with(prefix) { return Err(INVALID); }
|
if !s.starts_with(prefix) { return Err(INVALID); }
|
||||||
s = &s[prefix.len()..];
|
s = &s[prefix.len()..];
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
Item::OwnedLiteral(ref prefix) => {
|
&Item::OwnedLiteral(ref prefix) => {
|
||||||
if s.len() < prefix.len() { return Err(TOO_SHORT); }
|
if s.len() < prefix.len() { return Err(TOO_SHORT); }
|
||||||
if !s.starts_with(&prefix[..]) { return Err(INVALID); }
|
if !s.starts_with(&prefix[..]) { return Err(INVALID); }
|
||||||
s = &s[prefix.len()..];
|
s = &s[prefix.len()..];
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Space(_) => {
|
&Item::Space(_) => {
|
||||||
s = s.trim_left();
|
s = s.trim_left();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "alloc", feature = "std", test))]
|
#[cfg(any(feature = "alloc", feature = "std", test))]
|
||||||
Item::OwnedSpace(_) => {
|
&Item::OwnedSpace(_) => {
|
||||||
s = s.trim_left();
|
s = s.trim_left();
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Numeric(spec, _pad) => {
|
&Item::Numeric(ref spec, ref _pad) => {
|
||||||
use super::Numeric::*;
|
use super::Numeric::*;
|
||||||
type Setter = fn(&mut Parsed, i64) -> ParseResult<()>;
|
type Setter = fn(&mut Parsed, i64) -> ParseResult<()>;
|
||||||
|
|
||||||
let (width, signed, set): (usize, bool, Setter) = match spec {
|
let (width, signed, set): (usize, bool, Setter) = match spec {
|
||||||
Year => (4, true, Parsed::set_year),
|
&Year => (4, true, Parsed::set_year),
|
||||||
YearDiv100 => (2, false, Parsed::set_year_div_100),
|
&YearDiv100 => (2, false, Parsed::set_year_div_100),
|
||||||
YearMod100 => (2, false, Parsed::set_year_mod_100),
|
&YearMod100 => (2, false, Parsed::set_year_mod_100),
|
||||||
IsoYear => (4, true, Parsed::set_isoyear),
|
&IsoYear => (4, true, Parsed::set_isoyear),
|
||||||
IsoYearDiv100 => (2, false, Parsed::set_isoyear_div_100),
|
&IsoYearDiv100 => (2, false, Parsed::set_isoyear_div_100),
|
||||||
IsoYearMod100 => (2, false, Parsed::set_isoyear_mod_100),
|
&IsoYearMod100 => (2, false, Parsed::set_isoyear_mod_100),
|
||||||
Month => (2, false, Parsed::set_month),
|
&Month => (2, false, Parsed::set_month),
|
||||||
Day => (2, false, Parsed::set_day),
|
&Day => (2, false, Parsed::set_day),
|
||||||
WeekFromSun => (2, false, Parsed::set_week_from_sun),
|
&WeekFromSun => (2, false, Parsed::set_week_from_sun),
|
||||||
WeekFromMon => (2, false, Parsed::set_week_from_mon),
|
&WeekFromMon => (2, false, Parsed::set_week_from_mon),
|
||||||
IsoWeek => (2, false, Parsed::set_isoweek),
|
&IsoWeek => (2, false, Parsed::set_isoweek),
|
||||||
NumDaysFromSun => (1, false, set_weekday_with_num_days_from_sunday),
|
&NumDaysFromSun => (1, false, set_weekday_with_num_days_from_sunday),
|
||||||
WeekdayFromMon => (1, false, set_weekday_with_number_from_monday),
|
&WeekdayFromMon => (1, false, set_weekday_with_number_from_monday),
|
||||||
Ordinal => (3, false, Parsed::set_ordinal),
|
&Ordinal => (3, false, Parsed::set_ordinal),
|
||||||
Hour => (2, false, Parsed::set_hour),
|
&Hour => (2, false, Parsed::set_hour),
|
||||||
Hour12 => (2, false, Parsed::set_hour12),
|
&Hour12 => (2, false, Parsed::set_hour12),
|
||||||
Minute => (2, false, Parsed::set_minute),
|
&Minute => (2, false, Parsed::set_minute),
|
||||||
Second => (2, false, Parsed::set_second),
|
&Second => (2, false, Parsed::set_second),
|
||||||
Nanosecond => (9, false, Parsed::set_nanosecond),
|
&Nanosecond => (9, false, Parsed::set_nanosecond),
|
||||||
Timestamp => (usize::MAX, false, Parsed::set_timestamp),
|
&Timestamp => (usize::MAX, false, Parsed::set_timestamp),
|
||||||
|
|
||||||
// for the future expansion
|
// for the future expansion
|
||||||
Internal(ref int) => match int._dummy {},
|
&Internal(ref int) => match int._dummy {},
|
||||||
};
|
};
|
||||||
|
|
||||||
s = s.trim_left();
|
s = s.trim_left();
|
||||||
|
@ -282,31 +282,31 @@ pub fn parse<'a, I, B>(parsed: &mut Parsed, mut s: &str, items: I) -> ParseResul
|
||||||
try!(set(parsed, v));
|
try!(set(parsed, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Fixed(spec) => {
|
&Item::Fixed(ref spec) => {
|
||||||
use super::Fixed::*;
|
use super::Fixed::*;
|
||||||
|
|
||||||
match spec {
|
match spec {
|
||||||
ShortMonthName => {
|
&ShortMonthName => {
|
||||||
let month0 = try_consume!(scan::short_month0(s));
|
let month0 = try_consume!(scan::short_month0(s));
|
||||||
try!(parsed.set_month(i64::from(month0) + 1));
|
try!(parsed.set_month(i64::from(month0) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
LongMonthName => {
|
&LongMonthName => {
|
||||||
let month0 = try_consume!(scan::short_or_long_month0(s));
|
let month0 = try_consume!(scan::short_or_long_month0(s));
|
||||||
try!(parsed.set_month(i64::from(month0) + 1));
|
try!(parsed.set_month(i64::from(month0) + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
ShortWeekdayName => {
|
&ShortWeekdayName => {
|
||||||
let weekday = try_consume!(scan::short_weekday(s));
|
let weekday = try_consume!(scan::short_weekday(s));
|
||||||
try!(parsed.set_weekday(weekday));
|
try!(parsed.set_weekday(weekday));
|
||||||
}
|
}
|
||||||
|
|
||||||
LongWeekdayName => {
|
&LongWeekdayName => {
|
||||||
let weekday = try_consume!(scan::short_or_long_weekday(s));
|
let weekday = try_consume!(scan::short_or_long_weekday(s));
|
||||||
try!(parsed.set_weekday(weekday));
|
try!(parsed.set_weekday(weekday));
|
||||||
}
|
}
|
||||||
|
|
||||||
LowerAmPm | UpperAmPm => {
|
&LowerAmPm | &UpperAmPm => {
|
||||||
if s.len() < 2 { return Err(TOO_SHORT); }
|
if s.len() < 2 { return Err(TOO_SHORT); }
|
||||||
let ampm = match (s.as_bytes()[0] | 32, s.as_bytes()[1] | 32) {
|
let ampm = match (s.as_bytes()[0] | 32, s.as_bytes()[1] | 32) {
|
||||||
(b'a',b'm') => false,
|
(b'a',b'm') => false,
|
||||||
|
@ -317,56 +317,56 @@ pub fn parse<'a, I, B>(parsed: &mut Parsed, mut s: &str, items: I) -> ParseResul
|
||||||
s = &s[2..];
|
s = &s[2..];
|
||||||
}
|
}
|
||||||
|
|
||||||
Nanosecond | Nanosecond3 | Nanosecond6 | Nanosecond9 => {
|
&Nanosecond | &Nanosecond3 | &Nanosecond6 | &Nanosecond9 => {
|
||||||
if s.starts_with('.') {
|
if s.starts_with('.') {
|
||||||
let nano = try_consume!(scan::nanosecond(&s[1..]));
|
let nano = try_consume!(scan::nanosecond(&s[1..]));
|
||||||
try!(parsed.set_nanosecond(nano));
|
try!(parsed.set_nanosecond(nano));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Internal(InternalFixed { val: InternalInternal::Nanosecond3NoDot }) => {
|
&Internal(InternalFixed { val: InternalInternal::Nanosecond3NoDot }) => {
|
||||||
if s.len() < 3 { return Err(TOO_SHORT); }
|
if s.len() < 3 { return Err(TOO_SHORT); }
|
||||||
let nano = try_consume!(scan::nanosecond_fixed(s, 3));
|
let nano = try_consume!(scan::nanosecond_fixed(s, 3));
|
||||||
try!(parsed.set_nanosecond(nano));
|
try!(parsed.set_nanosecond(nano));
|
||||||
}
|
}
|
||||||
|
|
||||||
Internal(InternalFixed { val: InternalInternal::Nanosecond6NoDot }) => {
|
&Internal(InternalFixed { val: InternalInternal::Nanosecond6NoDot }) => {
|
||||||
if s.len() < 6 { return Err(TOO_SHORT); }
|
if s.len() < 6 { return Err(TOO_SHORT); }
|
||||||
let nano = try_consume!(scan::nanosecond_fixed(s, 6));
|
let nano = try_consume!(scan::nanosecond_fixed(s, 6));
|
||||||
try!(parsed.set_nanosecond(nano));
|
try!(parsed.set_nanosecond(nano));
|
||||||
}
|
}
|
||||||
|
|
||||||
Internal(InternalFixed { val: InternalInternal::Nanosecond9NoDot }) => {
|
&Internal(InternalFixed { val: InternalInternal::Nanosecond9NoDot }) => {
|
||||||
if s.len() < 9 { return Err(TOO_SHORT); }
|
if s.len() < 9 { return Err(TOO_SHORT); }
|
||||||
let nano = try_consume!(scan::nanosecond_fixed(s, 9));
|
let nano = try_consume!(scan::nanosecond_fixed(s, 9));
|
||||||
try!(parsed.set_nanosecond(nano));
|
try!(parsed.set_nanosecond(nano));
|
||||||
}
|
}
|
||||||
|
|
||||||
TimezoneName => return Err(BAD_FORMAT),
|
&TimezoneName => return Err(BAD_FORMAT),
|
||||||
|
|
||||||
TimezoneOffsetColon | TimezoneOffset => {
|
&TimezoneOffsetColon | &TimezoneOffset => {
|
||||||
let offset = try_consume!(scan::timezone_offset(s.trim_left(),
|
let offset = try_consume!(scan::timezone_offset(s.trim_left(),
|
||||||
scan::colon_or_space));
|
scan::colon_or_space));
|
||||||
try!(parsed.set_offset(i64::from(offset)));
|
try!(parsed.set_offset(i64::from(offset)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TimezoneOffsetColonZ | TimezoneOffsetZ => {
|
&TimezoneOffsetColonZ | &TimezoneOffsetZ => {
|
||||||
let offset = try_consume!(scan::timezone_offset_zulu(s.trim_left(),
|
let offset = try_consume!(scan::timezone_offset_zulu(s.trim_left(),
|
||||||
scan::colon_or_space));
|
scan::colon_or_space));
|
||||||
try!(parsed.set_offset(i64::from(offset)));
|
try!(parsed.set_offset(i64::from(offset)));
|
||||||
}
|
}
|
||||||
Internal(InternalFixed { val: InternalInternal::TimezoneOffsetPermissive }) => {
|
&Internal(InternalFixed { val: InternalInternal::TimezoneOffsetPermissive }) => {
|
||||||
let offset = try_consume!(scan::timezone_offset_permissive(
|
let offset = try_consume!(scan::timezone_offset_permissive(
|
||||||
s.trim_left(), scan::colon_or_space));
|
s.trim_left(), scan::colon_or_space));
|
||||||
try!(parsed.set_offset(i64::from(offset)));
|
try!(parsed.set_offset(i64::from(offset)));
|
||||||
}
|
}
|
||||||
|
|
||||||
RFC2822 => try_consume!(parse_rfc2822(parsed, s)),
|
&RFC2822 => try_consume!(parse_rfc2822(parsed, s)),
|
||||||
RFC3339 => try_consume!(parse_rfc3339(parsed, s)),
|
&RFC3339 => try_consume!(parse_rfc3339(parsed, s)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Item::Error => {
|
&Item::Error => {
|
||||||
return Err(BAD_FORMAT);
|
return Err(BAD_FORMAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ pub fn number(s: &str, min: usize, max: usize) -> ParseResult<(&str, i64)> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut n = 0i64;
|
let mut n = 0i64;
|
||||||
for (i, c) in bytes.iter().take(max).copied().enumerate() {
|
for (i, c) in bytes.iter().take(max).cloned().enumerate() { // cloned() = copied()
|
||||||
if c < b'0' || b'9' < c {
|
if c < b'0' || b'9' < c {
|
||||||
if i < min {
|
if i < min {
|
||||||
return Err(INVALID);
|
return Err(INVALID);
|
||||||
|
@ -58,7 +58,7 @@ pub fn number(s: &str, min: usize, max: usize) -> ParseResult<(&str, i64)> {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((&s[max.min(bytes.len())..], n))
|
Ok((&s[::core::cmp::min(max, bytes.len())..], n))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to consume at least one digits as a fractional second.
|
/// Tries to consume at least one digits as a fractional second.
|
||||||
|
|
Loading…
Reference in New Issue