@@ -331,24 +331,37 @@ pub fn is_whitespace(c: char) -> bool {
331
331
332
332
matches ! (
333
333
c,
334
- // Usual ASCII suspects
335
- '\u{0009}' // \t
336
- | '\u{000A}' // \n
334
+ // End-of-line characters
335
+ | '\u{000A}' // line feed (\n)
337
336
| '\u{000B}' // vertical tab
338
337
| '\u{000C}' // form feed
339
- | '\u{000D}' // \r
340
- | '\u{0020}' // space
341
-
342
- // NEXT LINE from latin1
343
- | '\u{0085}'
338
+ | '\u{000D}' // carriage return (\r)
339
+ | '\u{0085}' // next line (from latin1)
340
+ | '\u{2028}' // LINE SEPARATOR
341
+ | '\u{2029}' // PARAGRAPH SEPARATOR
344
342
345
- // Bidi markers
343
+ // `Default_Ignorable_Code_Point` characters
346
344
| '\u{200E}' // LEFT-TO-RIGHT MARK
347
345
| '\u{200F}' // RIGHT-TO-LEFT MARK
348
346
349
- // Dedicated whitespace characters from Unicode
350
- | '\u{2028}' // LINE SEPARATOR
351
- | '\u{2029}' // PARAGRAPH SEPARATOR
347
+ // Horizontal space characters
348
+ | '\u{0009}' // tab (\t)
349
+ | '\u{0020}' // space
350
+ )
351
+ }
352
+
353
+ /// True if `c` is considered horizontal whitespace according to Rust language definition.
354
+ pub fn is_horizontal_whitespace ( c : char ) -> bool {
355
+ // This is Pattern_White_Space.
356
+ //
357
+ // Note that this set is stable (ie, it doesn't change with different
358
+ // Unicode versions), so it's ok to just hard-code the values.
359
+
360
+ matches ! (
361
+ c,
362
+ // Horizontal space characters
363
+ '\u{0009}' // tab (\t)
364
+ | '\u{0020}' // space
352
365
)
353
366
}
354
367
@@ -538,7 +551,7 @@ impl Cursor<'_> {
538
551
debug_assert ! ( length_opening >= 3 ) ;
539
552
540
553
// whitespace between the opening and the infostring.
541
- self . eat_while ( |ch| ch != '\n' && is_whitespace ( ch) ) ;
554
+ self . eat_while ( |ch| ch != '\n' && is_horizontal_whitespace ( ch) ) ;
542
555
543
556
// copied from `eat_identifier`, but allows `-` and `.` in infostring to allow something like
544
557
// `---Cargo.toml` as a valid opener
@@ -547,7 +560,7 @@ impl Cursor<'_> {
547
560
self . eat_while ( |c| is_id_continue ( c) || c == '-' || c == '.' ) ;
548
561
}
549
562
550
- self . eat_while ( |ch| ch != '\n' && is_whitespace ( ch) ) ;
563
+ self . eat_while ( |ch| ch != '\n' && is_horizontal_whitespace ( ch) ) ;
551
564
let invalid_infostring = self . first ( ) != '\n' ;
552
565
553
566
let mut found = false ;
@@ -588,7 +601,7 @@ impl Cursor<'_> {
588
601
// on a standalone line. Might be wrong.
589
602
while let Some ( closing) = rest. find ( "---" ) {
590
603
let preceding_chars_start = rest[ ..closing] . rfind ( "\n " ) . map_or ( 0 , |i| i + 1 ) ;
591
- if rest[ preceding_chars_start..closing] . chars ( ) . all ( is_whitespace ) {
604
+ if rest[ preceding_chars_start..closing] . chars ( ) . all ( is_horizontal_whitespace ) {
592
605
// candidate found
593
606
potential_closing = Some ( closing) ;
594
607
break ;
0 commit comments