@@ -164,7 +164,7 @@ impl<'s> Ident<'s> {
164
164
165
165
let d = match punycode_bytes. next ( ) {
166
166
Some ( d @ b'a' ...b'z' ) => d - b'a' ,
167
- Some ( d @ b'A ' ...b'J ' ) => 26 + ( d - b'A ' ) ,
167
+ Some ( d @ b'0 ' ...b'9 ' ) => 26 + ( d - b'0 ' ) ,
168
168
_ => return Err ( ( ) ) ,
169
169
} ;
170
170
let d = d as usize ;
@@ -226,18 +226,12 @@ impl<'s> Display for Ident<'s> {
226
226
try!( f. write_str ( "punycode{" ) ) ;
227
227
228
228
// Reconstruct a standard Punycode encoding,
229
- // by using `-` as the separator and replacing
230
- // [A-J] with [0-9] (in the base36 codes).
229
+ // by using `-` as the separator.
231
230
if !self . ascii . is_empty ( ) {
232
231
try!( f. write_str ( self . ascii ) ) ;
233
232
try!( f. write_str ( "-" ) ) ;
234
233
}
235
- for mut b in self . punycode . bytes ( ) {
236
- if let b'A' ...b'J' = b {
237
- b = b - b'A' + b'0' ;
238
- }
239
- try!( ( b as char ) . fmt ( f) ) ;
240
- }
234
+ try!( f. write_str ( self . punycode ) ) ;
241
235
242
236
f. write_str ( "}" )
243
237
} else {
@@ -396,6 +390,9 @@ impl<'s> Parser<'s> {
396
390
}
397
391
}
398
392
393
+ // Skip past the optional `_` separator.
394
+ self . eat ( b'_' ) ;
395
+
399
396
let start = self . next ;
400
397
self . next = try!( self . next . checked_add ( len) . ok_or ( Invalid ) ) ;
401
398
if self . next > self . sym . len ( ) {
@@ -688,16 +685,7 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
688
685
let dis = parse ! ( self , disambiguator) ;
689
686
let name = parse ! ( self , ident) ;
690
687
691
- if name. punycode . is_empty ( ) {
692
- // Unescape `_[0-9_]`.
693
- let mut name = name. ascii ;
694
- if name. starts_with ( "_" ) {
695
- name = & name[ 1 ..] ;
696
- }
697
- try!( self . out . write_str ( name) ) ;
698
- } else {
699
- try!( name. fmt ( self . out ) ) ;
700
- }
688
+ try!( name. fmt ( self . out ) ) ;
701
689
if !self . out . alternate ( ) {
702
690
try!( self . out . write_str ( "[" ) ) ;
703
691
try!( fmt:: LowerHex :: fmt ( & dis, self . out ) ) ;
@@ -1015,10 +1003,18 @@ mod tests {
1015
1003
)
1016
1004
}
1017
1005
1006
+ #[ test]
1007
+ fn demangle_crate_with_leading_digit ( ) {
1008
+ t_nohash ! (
1009
+ "_RNvC6_123foo3bar" ,
1010
+ "123foo::bar"
1011
+ ) ;
1012
+ }
1013
+
1018
1014
#[ test]
1019
1015
fn demangle_utf8_idents ( ) {
1020
1016
t_nohash ! (
1021
- "_RNqCs4fqI2P2rA04_11utf8_identsu30___HhkackfeceaBcbdathfdhJhlqGy " ,
1017
+ "_RNqCs4fqI2P2rA04_11utf8_identsu30____7hkackfecea1cbdathfdh9hlq6y " ,
1022
1018
"utf8_idents::საჭმელად_გემრიელი_სადილი"
1023
1019
) ;
1024
1020
}
0 commit comments