crypto-inventory 0.3.0: Rust detector (use-resolved names, static calls, generics, ring constants, Noise patterns), Cargo.toml manifests, BLAKE3; 44/44, negative control 21/21
This commit is contained in:
1 parent
86779c8334
commit
f2f6217b4c
16 files changed
+942
-21
No files matched your search
@@ -15,6 +15,7 @@ export function curata(text, limbaj) {
|
||||
case 'java': return curataC(text, { textBlock: true });
|
||||
case 'go': return curataC(text, { raw: true });
|
||||
case 'python': return curataPython(text);
|
||||
case 'rust': return curataRust(text);
|
||||
default: return { code: text, siruri: [] };
|
||||
}
|
||||
}
|
||||
@@ -199,6 +200,73 @@ function curataPython(text) {
|
||||
return { code: out.join(''), siruri };
|
||||
}
|
||||
|
||||
// Rust (0.3.0): comentariile bloc se IMBRICA; sirurile pot trece peste randuri si au forme brute (r"...", r#"..."#, br"...",
|
||||
// cr#"..."#) si de octeti (b"..."); apostroful NU deschide un sir decat ca literal char ('a', '\n', '\u{1F600}', b'x'): altfel e
|
||||
// o durata de viata ('a, 'static) sau o eticheta ('outer:), si un lexer C ar fi deschis acolo un "sir" pana la urmatorul apostrof.
|
||||
function curataRust(text) {
|
||||
const n = text.length;
|
||||
const out = text.split('');
|
||||
const goleste = golitor(out);
|
||||
const siruri = [];
|
||||
let i = 0;
|
||||
while (i < n) {
|
||||
const c = text[i];
|
||||
const d = text[i + 1];
|
||||
if (d === '/' && c === '/') { // (scris invers fata de lexerul C: controlul negativ isi ancoreaza ciotul pe acela)
|
||||
let j = i;
|
||||
while (j < n && text[j] !== '\n') j++;
|
||||
goleste(i, j); i = j; continue;
|
||||
}
|
||||
if (c === '/' && d === '*') {
|
||||
let j = i + 2;
|
||||
let ad = 1;
|
||||
while (j < n && ad > 0) {
|
||||
if (text[j] === '/' && text[j + 1] === '*') { ad++; j += 2; continue; }
|
||||
if (text[j] === '*' && text[j + 1] === '/') { ad--; j += 2; continue; }
|
||||
j++;
|
||||
}
|
||||
goleste(i, j); i = j; continue;
|
||||
}
|
||||
const dupaCuvant = i > 0 && /\w/.test(text[i - 1]);
|
||||
if (!dupaCuvant && (c === 'r' || ((c === 'b' || c === 'c') && d === 'r'))) {
|
||||
let j = c === 'r' ? i + 1 : i + 2;
|
||||
let diezi = 0;
|
||||
while (text[j] === '#') { diezi++; j++; }
|
||||
if (text[j] === '"') {
|
||||
const inchidere = '"' + '#'.repeat(diezi);
|
||||
const k = text.indexOf(inchidere, j + 1);
|
||||
const sf = k < 0 ? n : k + inchidere.length;
|
||||
siruri.push([i, sf]); i = sf; continue;
|
||||
}
|
||||
}
|
||||
if (c === '"' || (!dupaCuvant && (c === 'b' || c === 'c') && d === '"')) {
|
||||
const start = i;
|
||||
let j = c === '"' ? i + 1 : i + 2;
|
||||
while (j < n && text[j] !== '"') { if (text[j] === '\\') j++; j++; }
|
||||
j = Math.min(n, j + 1);
|
||||
siruri.push([start, j]); i = j; continue;
|
||||
}
|
||||
if (c === "'") {
|
||||
if (d === '\\') {
|
||||
let j = i + 2;
|
||||
while (j < n && text[j] !== "'" && text[j] !== '\n' && j - i < 16) j++;
|
||||
if (text[j] === "'") { siruri.push([i, j + 1]); i = j + 1; continue; }
|
||||
i++; continue;
|
||||
}
|
||||
if (d !== undefined && d !== '\n' && text[i + 2] === "'") { siruri.push([i, i + 3]); i += 3; continue; }
|
||||
if (d !== undefined && d.charCodeAt(0) >= 0xd800 && d.charCodeAt(0) <= 0xdbff && text[i + 3] === "'") { siruri.push([i, i + 4]); i += 4; continue; }
|
||||
i++; continue;
|
||||
}
|
||||
if (/[A-Za-z_]/.test(c)) {
|
||||
let j = i + 1;
|
||||
while (j < n && /\w/.test(text[j])) j++;
|
||||
i = j; continue;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return { code: out.join(''), siruri };
|
||||
}
|
||||
|
||||
// cautare binara: pozitia e inauntrul unui sir?
|
||||
export function inSir(siruri, pos) {
|
||||
let lo = 0;
|
||||
|
||||
Reference in new issue
Block a user