@@ -13,19 +13,20 @@ pub(crate) struct HeaderLine<'ln> {
1313pub ( crate ) fn iter_header < ' ln > ( contents : & ' ln str , it : & mut dyn FnMut ( HeaderLine < ' ln > ) ) {
1414 for ln in contents. lines ( ) {
1515 let ln = ln. trim ( ) ;
16- if ln. starts_with ( COMMENT ) && ln[ COMMENT . len ( ) ..] . trim_start ( ) . starts_with ( '[' ) {
17- if let Some ( close_brace) = ln. find ( ']' ) {
18- let open_brace = ln. find ( '[' ) . unwrap ( ) ;
19- let revision = & ln[ open_brace + 1 ..close_brace] ;
20- it ( HeaderLine {
21- revision : Some ( revision) ,
22- directive : ln[ ( close_brace + 1 ) ..] . trim_start ( ) ,
23- } ) ;
24- } else {
25- panic ! ( "malformed condition directive: expected `//@[foo]`, found `{ln}`" )
26- }
27- } else if ln. starts_with ( COMMENT ) {
28- it ( HeaderLine { revision : None , directive : ln[ COMMENT . len ( ) ..] . trim_start ( ) } ) ;
16+
17+ // We're left with potentially `[rev]name: value`.
18+ let Some ( remainder) = ln. strip_prefix ( COMMENT ) else {
19+ continue ;
20+ } ;
21+
22+ if let Some ( remainder) = remainder. trim_start ( ) . strip_prefix ( '[' ) {
23+ let Some ( ( revision, remainder) ) = remainder. split_once ( ']' ) else {
24+ panic ! ( "malformed revision directive: expected `//@[rev]`, found `{ln}`" ) ;
25+ } ;
26+ // We trimmed off the `[rev]` portion, left with `name: value`.
27+ it ( HeaderLine { revision : Some ( revision) , directive : remainder. trim ( ) } ) ;
28+ } else {
29+ it ( HeaderLine { revision : None , directive : remainder. trim ( ) } ) ;
2930 }
3031 }
3132}
0 commit comments