Skip to content

Commit 0391e06

Browse files
committed
move to4digitHex to Numbers.qll
1 parent 03fbd38 commit 0391e06

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

shared/regex/codeql/regex/nfa/NfaUtils.qll

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
private import codeql.regex.RegexTreeView
6+
private import codeql.util.Numbers
67

78
/**
89
* Classes and predicates that create an NFA and various algorithms for working with it.
@@ -1330,18 +1331,6 @@ module Make<RegexTreeViewSig TreeImpl> {
13301331
else result = "\\u" + to4digitHex(any(int i | i.toUnicode() = char))
13311332
}
13321333

1333-
/**
1334-
* Gets a 4-digit hex representation of `i`.
1335-
*/
1336-
bindingset[i]
1337-
string to4digitHex(int i) {
1338-
result =
1339-
"0123456789abcdef".charAt(i.bitShiftRight(12).bitAnd(15)) +
1340-
"0123456789abcdef".charAt(i.bitShiftRight(8).bitAnd(15)) +
1341-
"0123456789abcdef".charAt(i.bitShiftRight(4).bitAnd(15)) +
1342-
"0123456789abcdef".charAt(i.bitAnd(15))
1343-
}
1344-
13451334
/** Holds if `char` is easily printable char, or whitespace. */
13461335
private predicate isPrintable(string char) {
13471336
exists(ascii(char))

shared/regex/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ version: 0.1.2-dev
33
groups: shared
44
library: true
55
dependencies:
6+
codeql/util: ${workspace}
67
warnOnImplicitThis: true

shared/util/codeql/util/Numbers.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ private int toHex(string hex) {
100100
result = 15 and hex = ["f", "F"]
101101
}
102102

103+
/**
104+
* Gets a 4-digit hex representation of `i`.
105+
*/
106+
bindingset[i]
107+
string to4digitHex(int i) {
108+
result =
109+
"0123456789abcdef".charAt(i.bitShiftRight(12).bitAnd(15)) +
110+
"0123456789abcdef".charAt(i.bitShiftRight(8).bitAnd(15)) +
111+
"0123456789abcdef".charAt(i.bitShiftRight(4).bitAnd(15)) +
112+
"0123456789abcdef".charAt(i.bitAnd(15))
113+
}
114+
103115
/**
104116
* Gets the value of 16 to the power of `n`. Holds only for `n` in the range
105117
* 0..7 (inclusive).

0 commit comments

Comments
 (0)