MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / countLoc

Function countLoc

Support/SingleFileLibs/javascript/amalgamationCore.js:44–57  ·  view source on GitHub ↗
(content)

Source from the content-addressed store, hash-verified

42}
43
44export function countLoc(content) {
45 let code = 0, comments = 0, inBlock = false;
46 const lines = content.split(/\r?\n/);
47 for (const line of lines) {
48 const s = line.trim();
49 if (!s) { comments++; continue; }
50 if (inBlock) { comments++; if (s.includes('*/')) inBlock = false; continue; }
51 if (s.startsWith('//')) { comments++; continue; }
52 if (s.startsWith('/*')) { comments++; if (!s.includes('*/')) inBlock = true; continue; }
53 code++;
54 }
55 comments--; // end of file newline
56 return { code, comments };
57}
58
59function normalizeContentForHash(content) {
60 return content.replace(/\r\n/g, '\n').replace(/\r/g, '\n');

Callers 1

buildLibraryRecordFunction · 0.70

Calls 2

trimMethod · 0.80
startsWithMethod · 0.80

Tested by

no test coverage detected