@@ -609,20 +609,26 @@ module ts {
609
609
return + ( text . substring ( start , pos ) ) ;
610
610
}
611
611
612
+ /**
613
+ * Scans the given number of hexadecimal digits in the text,
614
+ * returning -1 if the given number is unavailable.
615
+ */
612
616
function scanExactNumberOfHexDigits ( count : number ) : number {
613
- return scanHexDigits ( /*minCount*/ count , /*maxCount */ count ) ;
617
+ return scanHexDigits ( /*minCount*/ count , /*scanAsManyAsPossible */ false ) ;
614
618
}
615
619
620
+ /**
621
+ * Scans as many hexadecimal digits as are available in the text,
622
+ * returning -1 if the given number of digits was unavailable.
623
+ */
616
624
function scanMinimumNumberOfHexDigits ( count : number ) : number {
617
- return scanHexDigits ( /*minCount*/ count , /*maxCount */ undefined ) ;
625
+ return scanHexDigits ( /*minCount*/ count , /*scanAsManyAsPossible */ true ) ;
618
626
}
619
627
620
- function scanHexDigits ( minCount : number , maxCount ?: number ) : number {
621
- var maxCountSpecified = maxCount !== undefined ;
622
-
628
+ function scanHexDigits ( minCount : number , scanAsManyAsPossible : boolean ) : number {
623
629
var digits = 0 ;
624
630
var value = 0 ;
625
- while ( ! maxCountSpecified || digits < maxCount ) {
631
+ while ( digits < minCount || scanAsManyAsPossible ) {
626
632
var ch = text . charCodeAt ( pos ) ;
627
633
if ( ch >= CharacterCodes . _0 && ch <= CharacterCodes . _9 ) {
628
634
value = value * 16 + ch - CharacterCodes . _0 ;
@@ -777,22 +783,19 @@ module ts {
777
783
case CharacterCodes . doubleQuote :
778
784
return "\"" ;
779
785
case CharacterCodes . u :
786
+ // '\u{DDDDDDDD}'
780
787
if ( pos < len && text . charCodeAt ( pos ) === CharacterCodes . openBrace ) {
781
788
hasExtendedUnicodeEscape = true ;
782
789
pos ++ ;
783
790
return scanExtendedUnicodeEscape ( ) ;
784
791
}
785
792
786
- // fall through
793
+ // '\uDDDD'
794
+ return scanHexadecimalEscape ( /*numDigits*/ 4 )
795
+
787
796
case CharacterCodes . x :
788
- var escapedValue = scanExactNumberOfHexDigits ( ch === CharacterCodes . x ? 2 : 4 ) ;
789
- if ( escapedValue >= 0 ) {
790
- return String . fromCharCode ( escapedValue ) ;
791
- }
792
- else {
793
- error ( Diagnostics . Hexadecimal_digit_expected ) ;
794
- return ""
795
- }
797
+ // '\xDD'
798
+ return scanHexadecimalEscape ( /*numDigits*/ 2 )
796
799
797
800
// when encountering a LineContinuation (i.e. a backslash and a line terminator sequence),
798
801
// the line terminator is interpreted to be "the empty code unit sequence".
@@ -810,6 +813,18 @@ module ts {
810
813
}
811
814
}
812
815
816
+ function scanHexadecimalEscape ( numDigits : number ) : string {
817
+ var escapedValue = scanExactNumberOfHexDigits ( numDigits ) ;
818
+
819
+ if ( escapedValue >= 0 ) {
820
+ return String . fromCharCode ( escapedValue ) ;
821
+ }
822
+ else {
823
+ error ( Diagnostics . Hexadecimal_digit_expected ) ;
824
+ return ""
825
+ }
826
+ }
827
+
813
828
function scanExtendedUnicodeEscape ( ) : string {
814
829
var escapedValue = scanMinimumNumberOfHexDigits ( 1 ) ;
815
830
var isInvalidExtendedEscape = false ;
0 commit comments