From a018a5c3433e20a56f642082586f4e4d28469381 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 12 Sep 2013 00:50:19 -0700 Subject: [PATCH] Parse underscores in identifiers for format! Closes #9119 --- src/libstd/fmt/parse.rs | 4 ++-- src/test/run-pass/ifmt.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstd/fmt/parse.rs b/src/libstd/fmt/parse.rs index fd0e86d7a31..9888af9313b 100644 --- a/src/libstd/fmt/parse.rs +++ b/src/libstd/fmt/parse.rs @@ -554,7 +554,7 @@ impl<'self> Parser<'self> { /// characters. fn word(&mut self) -> &'self str { let start = match self.cur.clone().next() { - Some((pos, c)) if char::is_alphabetic(c) => { + Some((pos, c)) if char::is_XID_start(c) => { self.cur.next(); pos } @@ -563,7 +563,7 @@ impl<'self> Parser<'self> { let mut end; loop { match self.cur.clone().next() { - Some((_, c)) if char::is_alphanumeric(c) => { + Some((_, c)) if char::is_XID_continue(c) => { self.cur.next(); } Some((pos, _)) => { end = pos; break } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index ab66bfc1011..0b2203be9d7 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -82,6 +82,7 @@ pub fn main() { t!(format!("{foo} {1} {bar} {0}", 0, 1, foo=2, bar=3), "2 1 3 0"); t!(format!("{} {0:s}", "a"), "a a"); t!(format!("{} {0}", "a"), "a a"); + t!(format!("{foo_bar}", foo_bar=1), "1"); // Methods should probably work t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 0u), "c0");