@@ -13,19 +13,20 @@ pub(crate) struct HeaderLine<'ln> {
13
13
pub ( crate ) fn iter_header < ' ln > ( contents : & ' ln str , it : & mut dyn FnMut ( HeaderLine < ' ln > ) ) {
14
14
for ln in contents. lines ( ) {
15
15
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 ( ) } ) ;
29
30
}
30
31
}
31
32
}
0 commit comments