@@ -368,7 +368,9 @@ impl Pandocs {
368
368
while pos < attrs. width {
369
369
let ( len, is_unused, name) = match fields. peek ( ) {
370
370
// If we are at the edge of a "used" field, use it
371
- Some ( field) if field. start == pos => ( field. len , false , field. name ) ,
371
+ Some ( field) if field. start == pos => {
372
+ ( field. len , false , field. name . as_ref ( ) )
373
+ }
372
374
// If in an unused field, end at the next field, or the width if none such
373
375
res => ( res. map_or ( attrs. width , |field| field. start ) - pos, true , "" ) ,
374
376
} ;
@@ -434,7 +436,7 @@ fn find_bit_descrs(
434
436
#[ derive( Debug ) ]
435
437
struct BitDescrAttrs < ' input > {
436
438
width : usize ,
437
- rows : Vec < ( & ' input str , Vec < BitDescrField < ' input > > ) > ,
439
+ rows : Vec < ( Cow < ' input , str > , Vec < BitDescrField < ' input > > ) > ,
438
440
increasing : bool ,
439
441
}
440
442
@@ -483,6 +485,13 @@ impl<'input> BitDescrAttrs<'input> {
483
485
for row_str in s. split_terminator ( ';' ) {
484
486
let row_str = row_str. trim ( ) ;
485
487
488
+ fn undo_escapes ( escaped : & str ) -> Cow < ' _ , str > {
489
+ lazy_static ! {
490
+ static ref RE : Regex = Regex :: new( r#"\\(\[|\])"# ) . unwrap( ) ;
491
+ }
492
+ RE . replace_all ( escaped, "$1" )
493
+ }
494
+
486
495
fn parse_name ( row_str : & str ) -> Option < usize > {
487
496
if !row_str. starts_with ( '"' ) {
488
497
return None ;
@@ -496,7 +505,7 @@ impl<'input> BitDescrAttrs<'input> {
496
505
"Expected row to begin by its name (did you forget to put quotes around it?)"
497
506
) ;
498
507
} ;
499
- let name = & row_str[ 1 ..( name_len + 1 ) ] ;
508
+ let name = undo_escapes ( & row_str[ 1 ..( name_len + 1 ) ] ) ;
500
509
let mut row_str = row_str[ ( name_len + 2 ) ..] . trim_start ( ) ; // The end is already trimmed.
501
510
502
511
// Then, the fields!
@@ -515,7 +524,7 @@ impl<'input> BitDescrAttrs<'input> {
515
524
let right = cap
516
525
. get ( 2 )
517
526
. map_or ( left, |end_match| end_match. as_str ( ) . parse ( ) . unwrap ( ) ) ;
518
- let name = & cap. get ( 3 ) . unwrap ( ) . as_str ( ) ;
527
+ let name = undo_escapes ( & cap. get ( 3 ) . unwrap ( ) . as_str ( ) ) ;
519
528
520
529
// Perform some sanity checks.
521
530
let Some ( ( mut start, len) ) = if increasing {
@@ -584,7 +593,7 @@ impl<'input> BitDescrAttrs<'input> {
584
593
struct BitDescrField < ' a > {
585
594
start : usize ,
586
595
len : usize ,
587
- name : & ' a str ,
596
+ name : Cow < ' a , str > ,
588
597
}
589
598
590
599
impl BitDescrField < ' _ > {
0 commit comments