cpp-merge
Version:
Command line tool to produce single source file from multiple C/C++ files
35 lines • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.limitLineLength = exports.removeDoubleEmptyLines = void 0;
const os_1 = require("os");
const doubleLineRegExp = new RegExp(`(${os_1.EOL}){2,}`, 'g');
const doubleLineReplaceValue = `$1${os_1.EOL}`;
function removeDoubleEmptyLines(content) {
return content.replace(doubleLineRegExp, doubleLineReplaceValue);
}
exports.removeDoubleEmptyLines = removeDoubleEmptyLines;
function limitLineLength(text, lineLength) {
if (lineLength <= 0 || text.length <= lineLength) {
return [text];
}
const resultLines = [];
const textLines = text.split(os_1.EOL);
for (const textLine of textLines) {
let rest = textLine;
while (rest.length > lineLength) {
const part = rest.substring(0, lineLength + 1);
const spacePosition = part.lastIndexOf(' ');
if (spacePosition > 0) {
resultLines.push(part.substring(0, spacePosition));
rest = rest.substring(spacePosition + 1);
continue;
}
resultLines.push(part.substring(0, lineLength));
rest = rest.substring(lineLength);
}
resultLines.push(rest);
}
return resultLines;
}
exports.limitLineLength = limitLineLength;
//# sourceMappingURL=stringUtils.js.map