@@ -470,6 +470,8 @@ module Impl implements RegexTreeViewSig {
470470 override string getPrimaryQLClass ( ) { result = "RegExpAlt" }
471471 }
472472
473+ private import codeql.util.Numbers as Numbers
474+
473475 /**
474476 * An escaped regular expression term, that is, a regular expression
475477 * term starting with a backslash, which is not a backreference.
@@ -531,11 +533,7 @@ module Impl implements RegexTreeViewSig {
531533 * Gets the unicode char for this escape.
532534 * E.g. for `\u0061` this returns "a".
533535 */
534- private string getUnicode ( ) {
535- exists ( int codepoint | codepoint = sum ( this .getHexValueFromUnicode ( _) ) |
536- result = codepoint .toUnicode ( )
537- )
538- }
536+ private string getUnicode ( ) { result = Numbers:: parseHexInt ( this .getHexString ( ) ) .toUnicode ( ) }
539537
540538 /** Gets the part of this escape that is a hexidecimal string */
541539 private string getHexString ( ) {
@@ -547,18 +545,6 @@ module Impl implements RegexTreeViewSig {
547545 then result = this .getText ( ) .substring ( 3 , this .getText ( ) .length ( ) - 1 )
548546 else result = this .getText ( ) .suffix ( 2 ) // \xhh
549547 }
550-
551- /**
552- * Gets int value for the `index`th char in the hex number of the unicode escape.
553- * E.g. for `\u0061` and `index = 2` this returns 96 (the number `6` interpreted as hex).
554- */
555- private int getHexValueFromUnicode ( int index ) {
556- this .isUnicode ( ) and
557- exists ( string hex , string char | hex = this .getHexString ( ) |
558- char = hex .charAt ( index ) and
559- result = 16 .pow ( hex .length ( ) - index - 1 ) * toHex ( char )
560- )
561- }
562548 }
563549
564550 /**
@@ -586,25 +572,6 @@ module Impl implements RegexTreeViewSig {
586572 RegExpNonWordBoundary ( ) { this .getChar ( ) = "\\B" }
587573 }
588574
589- /**
590- * Gets the hex number for the `hex` char.
591- */
592- private int toHex ( string hex ) {
593- result = [ 0 .. 9 ] and hex = result .toString ( )
594- or
595- result = 10 and hex = [ "a" , "A" ]
596- or
597- result = 11 and hex = [ "b" , "B" ]
598- or
599- result = 12 and hex = [ "c" , "C" ]
600- or
601- result = 13 and hex = [ "d" , "D" ]
602- or
603- result = 14 and hex = [ "e" , "E" ]
604- or
605- result = 15 and hex = [ "f" , "F" ]
606- }
607-
608575 /**
609576 * A character class escape in a regular expression.
610577 * That is, an escaped character that denotes multiple characters.
0 commit comments