@@ -475,6 +475,37 @@ where
475
475
u8:: from_str_radix ( & octet_content, 8 ) . unwrap ( ) as char
476
476
}
477
477
478
+ fn parse_unicode_name ( & mut self ) -> Result < char , LexicalError > {
479
+ let start_pos = self . get_pos ( ) ;
480
+ match self . next_char ( ) {
481
+ Some ( '{' ) => { }
482
+ _ => {
483
+ return Err ( LexicalError {
484
+ error : LexicalErrorType :: StringError ,
485
+ location : start_pos,
486
+ } )
487
+ }
488
+ }
489
+ let start_pos = self . get_pos ( ) ;
490
+ let mut name = String :: new ( ) ;
491
+ loop {
492
+ match self . next_char ( ) {
493
+ Some ( '}' ) => break ,
494
+ Some ( c) => name. push ( c) ,
495
+ None => {
496
+ return Err ( LexicalError {
497
+ error : LexicalErrorType :: StringError ,
498
+ location : self . get_pos ( ) ,
499
+ } )
500
+ }
501
+ }
502
+ }
503
+ unicode_names2:: character ( & name) . ok_or ( LexicalError {
504
+ error : LexicalErrorType :: UnicodeError ,
505
+ location : start_pos,
506
+ } )
507
+ }
508
+
478
509
fn lex_string (
479
510
& mut self ,
480
511
is_bytes : bool ,
@@ -532,11 +563,14 @@ where
532
563
Some ( 't' ) => {
533
564
string_content. push ( '\t' ) ;
534
565
}
535
- Some ( 'u' ) => string_content. push ( self . unicode_literal ( 4 ) ?) ,
536
- Some ( 'U' ) => string_content. push ( self . unicode_literal ( 8 ) ?) ,
537
- Some ( 'x' ) => string_content. push ( self . unicode_literal ( 2 ) ?) ,
538
566
Some ( 'v' ) => string_content. push ( '\x0b' ) ,
539
567
Some ( o @ '0' ..='7' ) => string_content. push ( self . parse_octet ( o) ) ,
568
+ Some ( 'x' ) => string_content. push ( self . unicode_literal ( 2 ) ?) ,
569
+ Some ( 'u' ) if !is_bytes => string_content. push ( self . unicode_literal ( 4 ) ?) ,
570
+ Some ( 'U' ) if !is_bytes => string_content. push ( self . unicode_literal ( 8 ) ?) ,
571
+ Some ( 'N' ) if !is_bytes => {
572
+ string_content. push ( self . parse_unicode_name ( ) ?)
573
+ }
540
574
Some ( c) => {
541
575
string_content. push ( '\\' ) ;
542
576
string_content. push ( c) ;
0 commit comments