Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### ⚠ BREAKING CHANGES

* `split`/`extract`: has become `async`, has changed signature and is scoped under `IfcSplitter`, exposed events (`onProgress`, `onSplitsResolved`, `onExtractWarning`) instead of console logs.

## [3.4.0](https://github.com/ThatOpen/engine_fragment/compare/v3.3.2...v3.4.0) (2026-04-09)


Expand Down
3 changes: 3 additions & 0 deletions packages/fragments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
"test-node": "yarn tsx ./src/Importers/IfcImporter/node-example.ts",
"test-indexes": "yarn tsx ./src/FragmentsModels/test-indexes.ts"
},
"engines": {
"node": ">=17"
},
"dependencies": {
"earcut": "^3.0.1",
"flatbuffers": "25.2.10",
Expand Down
100 changes: 100 additions & 0 deletions packages/fragments/src/Utils/ifc-parsing-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// ---------------------------------------------------------------------------
// Parse helpers — manual charCode-based extractors for speed on 37M+ lines
// ---------------------------------------------------------------------------
interface LineMeta {
id: number;
type: string;
}

export function extractLineMeta(raw: string): LineMeta | null {
if (raw.charCodeAt(0) !== 35) return null; // '#'
let id = 0;
let i = 1;
while (i < raw.length) {
const c = raw.charCodeAt(i);
if (c >= 48 && c <= 57) {
id = id * 10 + (c - 48);
i++;
} else break;
}
if (id === 0) return null;
while (i < raw.length && raw.charCodeAt(i) <= 32) i++;
if (raw.charCodeAt(i) !== 61) return null; // '='
i++;
while (i < raw.length && raw.charCodeAt(i) <= 32) i++;
const ts = i;
while (i < raw.length) {
const c = raw.charCodeAt(i);
if ((c >= 65 && c <= 90) || (c >= 48 && c <= 57) || c === 95) i++;
else break;
}
if (i === ts) return null;
return { id, type: raw.substring(ts, i) };
}

export function extractRefs(raw: string, skipId?: number): number[] {
const refs: number[] = [];
for (let i = 0; i < raw.length; i++) {
if (raw.charCodeAt(i) === 35) {
// '#'
let id = 0;
i++;
while (i < raw.length) {
const c = raw.charCodeAt(i);
if (c >= 48 && c <= 57) {
id = id * 10 + (c - 48);
i++;
} else break;
}
if (id > 0 && id !== skipId) refs.push(id);
i--; // outer loop will i++
}
}
return refs;
}

export function splitIfcArgs(s: string): string[] {
const args: string[] = [];
let depth = 0;
let inStr = false;
let current = "";
for (let i = 0; i < s.length; i++) {
const ch = s[i];
if (ch === "'" && !inStr) {
inStr = true;
current += ch;
} else if (ch === "'" && inStr) {
inStr = false;
current += ch;
} else if (inStr) {
current += ch;
} else if (ch === "(") {
depth++;
current += ch;
} else if (ch === ")") {
depth--;
current += ch;
} else if (ch === "," && depth === 0) {
args.push(current.trim());
current = "";
} else {
current += ch;
}
}
if (current.trim()) args.push(current.trim());
return args;
}

export function parseHashRef(s: string): number | null {
const m = s.trim().match(/^#(\d+)$/);
return m ? parseInt(m[1], 10) : null;
}

export function extractArgsString(raw: string | undefined): string | null {
if (!raw) return null;
const idx = raw.indexOf("(");
if (idx < 0) return null;
const lastParen = raw.lastIndexOf(")");
if (lastParen < 0) return null;
return raw.substring(idx + 1, lastParen);
}
Loading