|
1 | | -// We want to be able to build this crate with a stable compiler, so feature |
2 | | -// flags should be optional. |
3 | | -#![cfg_attr(not(feature = "unicode-xid"), feature(unicode_internals))] |
| 1 | +// We want to be able to build this crate with a stable compiler, so no |
| 2 | +// `#![feature]` attributes should be added. |
4 | 3 |
|
5 | 4 | mod cursor; |
6 | 5 | pub mod unescape; |
@@ -507,54 +506,52 @@ impl Cursor<'_> { |
507 | 506 | } |
508 | 507 |
|
509 | 508 | pub mod character_properties { |
510 | | - // this is Pattern_White_Space |
511 | | - #[cfg(feature = "unicode-xid")] |
| 509 | + // See [UAX #31](http://unicode.org/reports/tr31) for definitions of these |
| 510 | + // classes. |
| 511 | + |
| 512 | + // This is Pattern_White_Space. |
| 513 | + // |
| 514 | + // Note that this set is stable (ie, it doesn't change with different |
| 515 | + // Unicode versions), so it's ok to just hard-code the values. |
512 | 516 | pub fn is_whitespace(c: char) -> bool { |
513 | 517 | match c { |
514 | | - '\u{0009}' | '\u{000A}' | '\u{000B}' | '\u{000C}' | '\u{000D}' | '\u{0020}' |
515 | | - | '\u{0085}' | '\u{200E}' | '\u{200F}' | '\u{2028}' | '\u{2029}' => true, |
| 518 | + // Usual ASCII suspects |
| 519 | + | '\u{0009}' // \t |
| 520 | + | '\u{000A}' // \n |
| 521 | + | '\u{000B}' // vertical tab |
| 522 | + | '\u{000C}' // form feed |
| 523 | + | '\u{000D}' // \r |
| 524 | + | '\u{0020}' // space |
| 525 | + |
| 526 | + // NEXT LINE from latin1 |
| 527 | + | '\u{0085}' |
| 528 | + |
| 529 | + // Bidi markers |
| 530 | + | '\u{200E}' // LEFT-TO-RIGHT MARK |
| 531 | + | '\u{200F}' // RIGHT-TO-LEFT MARK |
| 532 | + |
| 533 | + // Dedicated whitespace characters from Unicode |
| 534 | + | '\u{2028}' // LINE SEPARATOR |
| 535 | + | '\u{2029}' // PARAGRAPH SEPARATOR |
| 536 | + => true, |
516 | 537 | _ => false, |
517 | 538 | } |
518 | 539 | } |
519 | 540 |
|
520 | | - #[cfg(not(feature = "unicode-xid"))] |
521 | | - pub fn is_whitespace(c: char) -> bool { |
522 | | - core::unicode::property::Pattern_White_Space(c) |
523 | | - } |
524 | | - |
525 | | - // this is XID_Start OR '_' (which formally is not a XID_Start) |
526 | | - #[cfg(feature = "unicode-xid")] |
| 541 | + // This is XID_Start OR '_' (which formally is not a XID_Start). |
527 | 542 | pub fn is_id_start(c: char) -> bool { |
528 | 543 | ('a' <= c && c <= 'z') |
529 | 544 | || ('A' <= c && c <= 'Z') |
530 | 545 | || c == '_' |
531 | 546 | || (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c)) |
532 | 547 | } |
533 | 548 |
|
534 | | - #[cfg(not(feature = "unicode-xid"))] |
535 | | - pub fn is_id_start(c: char) -> bool { |
536 | | - ('a' <= c && c <= 'z') |
537 | | - || ('A' <= c && c <= 'Z') |
538 | | - || c == '_' |
539 | | - || (c > '\x7f' && c.is_xid_start()) |
540 | | - } |
541 | | - |
542 | | - // this is XID_Continue |
543 | | - #[cfg(feature = "unicode-xid")] |
| 549 | + // This is XID_Continue. |
544 | 550 | pub fn is_id_continue(c: char) -> bool { |
545 | 551 | ('a' <= c && c <= 'z') |
546 | 552 | || ('A' <= c && c <= 'Z') |
547 | 553 | || ('0' <= c && c <= '9') |
548 | 554 | || c == '_' |
549 | 555 | || (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c)) |
550 | 556 | } |
551 | | - |
552 | | - #[cfg(not(feature = "unicode-xid"))] |
553 | | - pub fn is_id_continue(c: char) -> bool { |
554 | | - ('a' <= c && c <= 'z') |
555 | | - || ('A' <= c && c <= 'Z') |
556 | | - || ('0' <= c && c <= '9') |
557 | | - || c == '_' |
558 | | - || (c > '\x7f' && c.is_xid_continue()) |
559 | | - } |
560 | 557 | } |
0 commit comments