Remove unstable slice pattern
This commit is contained in:
parent
533161cfd7
commit
878b81d72f
|
@ -291,9 +291,9 @@ pub fn parse<'a, I>(parsed: &mut Parsed, mut s: &str, items: I) -> ParseResult<(
|
||||||
|
|
||||||
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,
|
||||||
[b'p',b'm'] => true,
|
(b'p',b'm') => true,
|
||||||
_ => return Err(INVALID)
|
_ => return Err(INVALID)
|
||||||
};
|
};
|
||||||
try!(parsed.set_ampm(ampm));
|
try!(parsed.set_ampm(ampm));
|
||||||
|
|
|
@ -64,19 +64,19 @@ pub fn nanosecond(s: &str) -> ParseResult<(&str, i64)> {
|
||||||
pub fn short_month0(s: &str) -> ParseResult<(&str, u8)> {
|
pub fn short_month0(s: &str) -> ParseResult<(&str, u8)> {
|
||||||
if s.len() < 3 { return Err(TOO_SHORT); }
|
if s.len() < 3 { return Err(TOO_SHORT); }
|
||||||
let buf = s.as_bytes();
|
let buf = s.as_bytes();
|
||||||
let month0 = match [buf[0] | 32, buf[1] | 32, buf[2] | 32] {
|
let month0 = match (buf[0] | 32, buf[1] | 32, buf[2] | 32) {
|
||||||
[b'j',b'a',b'n'] => 0,
|
(b'j',b'a',b'n') => 0,
|
||||||
[b'f',b'e',b'b'] => 1,
|
(b'f',b'e',b'b') => 1,
|
||||||
[b'm',b'a',b'r'] => 2,
|
(b'm',b'a',b'r') => 2,
|
||||||
[b'a',b'p',b'r'] => 3,
|
(b'a',b'p',b'r') => 3,
|
||||||
[b'm',b'a',b'y'] => 4,
|
(b'm',b'a',b'y') => 4,
|
||||||
[b'j',b'u',b'n'] => 5,
|
(b'j',b'u',b'n') => 5,
|
||||||
[b'j',b'u',b'l'] => 6,
|
(b'j',b'u',b'l') => 6,
|
||||||
[b'a',b'u',b'g'] => 7,
|
(b'a',b'u',b'g') => 7,
|
||||||
[b's',b'e',b'p'] => 8,
|
(b's',b'e',b'p') => 8,
|
||||||
[b'o',b'c',b't'] => 9,
|
(b'o',b'c',b't') => 9,
|
||||||
[b'n',b'o',b'v'] => 10,
|
(b'n',b'o',b'v') => 10,
|
||||||
[b'd',b'e',b'c'] => 11,
|
(b'd',b'e',b'c') => 11,
|
||||||
_ => return Err(INVALID)
|
_ => return Err(INVALID)
|
||||||
};
|
};
|
||||||
Ok((&s[3..], month0))
|
Ok((&s[3..], month0))
|
||||||
|
@ -86,14 +86,14 @@ pub fn short_month0(s: &str) -> ParseResult<(&str, u8)> {
|
||||||
pub fn short_weekday(s: &str) -> ParseResult<(&str, Weekday)> {
|
pub fn short_weekday(s: &str) -> ParseResult<(&str, Weekday)> {
|
||||||
if s.len() < 3 { return Err(TOO_SHORT); }
|
if s.len() < 3 { return Err(TOO_SHORT); }
|
||||||
let buf = s.as_bytes();
|
let buf = s.as_bytes();
|
||||||
let weekday = match [buf[0] | 32, buf[1] | 32, buf[2] | 32] {
|
let weekday = match (buf[0] | 32, buf[1] | 32, buf[2] | 32) {
|
||||||
[b'm',b'o',b'n'] => Weekday::Mon,
|
(b'm',b'o',b'n') => Weekday::Mon,
|
||||||
[b't',b'u',b'e'] => Weekday::Tue,
|
(b't',b'u',b'e') => Weekday::Tue,
|
||||||
[b'w',b'e',b'd'] => Weekday::Wed,
|
(b'w',b'e',b'd') => Weekday::Wed,
|
||||||
[b't',b'h',b'u'] => Weekday::Thu,
|
(b't',b'h',b'u') => Weekday::Thu,
|
||||||
[b'f',b'r',b'i'] => Weekday::Fri,
|
(b'f',b'r',b'i') => Weekday::Fri,
|
||||||
[b's',b'a',b't'] => Weekday::Sat,
|
(b's',b'a',b't') => Weekday::Sat,
|
||||||
[b's',b'u',b'n'] => Weekday::Sun,
|
(b's',b'u',b'n') => Weekday::Sun,
|
||||||
_ => return Err(INVALID)
|
_ => return Err(INVALID)
|
||||||
};
|
};
|
||||||
Ok((&s[3..], weekday))
|
Ok((&s[3..], weekday))
|
||||||
|
@ -167,6 +167,14 @@ pub fn colon_or_space(s: &str) -> ParseResult<&str> {
|
||||||
/// between hours and minutes, and should return either a new suffix or `Err` when parsing fails.
|
/// between hours and minutes, and should return either a new suffix or `Err` when parsing fails.
|
||||||
pub fn timezone_offset<F>(mut s: &str, mut colon: F) -> ParseResult<(&str, i32)>
|
pub fn timezone_offset<F>(mut s: &str, mut colon: F) -> ParseResult<(&str, i32)>
|
||||||
where F: FnMut(&str) -> ParseResult<&str> {
|
where F: FnMut(&str) -> ParseResult<&str> {
|
||||||
|
fn digits(s: &str) -> ParseResult<(u8, u8)> {
|
||||||
|
let b = s.as_bytes();
|
||||||
|
if b.len() < 2 {
|
||||||
|
Err(TOO_SHORT)
|
||||||
|
} else {
|
||||||
|
Ok((b[0], b[1]))
|
||||||
|
}
|
||||||
|
}
|
||||||
let negative = match s.as_bytes().first() {
|
let negative = match s.as_bytes().first() {
|
||||||
Some(&b'+') => false,
|
Some(&b'+') => false,
|
||||||
Some(&b'-') => true,
|
Some(&b'-') => true,
|
||||||
|
@ -176,9 +184,8 @@ pub fn timezone_offset<F>(mut s: &str, mut colon: F) -> ParseResult<(&str, i32)>
|
||||||
s = &s[1..];
|
s = &s[1..];
|
||||||
|
|
||||||
// hours (00--99)
|
// hours (00--99)
|
||||||
let hours = match s.as_bytes() {
|
let hours = match try!(digits(s)) {
|
||||||
[h1 @ b'0'...b'9', h2 @ b'0'...b'9', ..] => ((h1 - b'0') * 10 + (h2 - b'0')) as i32,
|
(h1 @ b'0'...b'9', h2 @ b'0'...b'9') => ((h1 - b'0') * 10 + (h2 - b'0')) as i32,
|
||||||
[] | [_] => return Err(TOO_SHORT),
|
|
||||||
_ => return Err(INVALID),
|
_ => return Err(INVALID),
|
||||||
};
|
};
|
||||||
s = &s[2..];
|
s = &s[2..];
|
||||||
|
@ -187,10 +194,9 @@ pub fn timezone_offset<F>(mut s: &str, mut colon: F) -> ParseResult<(&str, i32)>
|
||||||
s = try!(colon(s));
|
s = try!(colon(s));
|
||||||
|
|
||||||
// minutes (00--59)
|
// minutes (00--59)
|
||||||
let minutes = match s.as_bytes() {
|
let minutes = match try!(digits(s)) {
|
||||||
[m1 @ b'0'...b'5', m2 @ b'0'...b'9', ..] => ((m1 - b'0') * 10 + (m2 - b'0')) as i32,
|
(m1 @ b'0'...b'5', m2 @ b'0'...b'9') => ((m1 - b'0') * 10 + (m2 - b'0')) as i32,
|
||||||
[b'6'...b'9', b'0'...b'9', ..] => return Err(OUT_OF_RANGE),
|
(b'6'...b'9', b'0'...b'9') => return Err(OUT_OF_RANGE),
|
||||||
[] | [_] => return Err(TOO_SHORT),
|
|
||||||
_ => return Err(INVALID),
|
_ => return Err(INVALID),
|
||||||
};
|
};
|
||||||
s = &s[2..];
|
s = &s[2..];
|
||||||
|
|
|
@ -267,7 +267,6 @@ Advanced time zone handling is not yet supported (but is planned in 0.3).
|
||||||
|
|
||||||
#![doc(html_root_url = "https://lifthrasiir.github.io/rust-chrono/")]
|
#![doc(html_root_url = "https://lifthrasiir.github.io/rust-chrono/")]
|
||||||
|
|
||||||
#![feature(slice_patterns)]
|
|
||||||
#![feature(core, std_misc, zero_one)] // lib stability features as per RFC #507
|
#![feature(core, std_misc, zero_one)] // lib stability features as per RFC #507
|
||||||
#![cfg_attr(test, feature(test))] // ditto
|
#![cfg_attr(test, feature(test))] // ditto
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
|
|
Loading…
Reference in New Issue