ai-pp3
Version:
CLI tool combining multimodal AI analysis with RawTherapee's engine to generate optimized PP3 profiles for RAW photography
91 lines • 3.31 kB
JavaScript
// Section parsing functionality extracted from agent.ts
function createSectionParseState() {
return {
currentSection: "",
currentSectionName: "",
sectionIndex: 0,
inSection: false,
};
}
function finalizePreviousSection(state, sections, processSection) {
if (state.inSection && state.currentSection) {
const trimmedSection = state.currentSection.trim();
sections.push(trimmedSection);
if (processSection) {
processSection(trimmedSection, state.currentSectionName, state.sectionIndex);
}
state.sectionIndex++;
}
}
function startNewSection(line, trimmedLine, state, sectionOrders) {
const sectionName = trimmedLine.slice(1, -1);
state.currentSection = line;
state.currentSectionName = sectionName;
sectionOrders.push(sectionName);
state.inSection = true;
}
function handleSectionLine(line, state) {
const trimmedLine = line.trim();
if (trimmedLine.startsWith("[")) {
return; // This case is handled by the caller
}
if (state.inSection) {
state.currentSection += `\n${line}`;
}
}
/**
* Base function to split content into sections based on section headers in square brackets
* @param content - The content to split into sections
* @param processSection - Optional callback to process each section as it's found
* @returns Object containing sections and their order
*/
export function splitContentBySections(content, processSection) {
if (!content.trim()) {
return { sections: [], sectionOrders: [] };
}
const lines = content.split("\n");
const sections = [];
const sectionOrders = [];
const state = createSectionParseState();
for (const line of lines) {
const trimmedLine = line.trim();
if (trimmedLine.startsWith("[")) {
finalizePreviousSection(state, sections, processSection);
startNewSection(line, trimmedLine, state, sectionOrders);
}
else {
handleSectionLine(line, state);
}
}
// Handle the last section
finalizePreviousSection(state, sections, processSection);
return { sections, sectionOrders };
}
/**
* Splits PP3 content into sections and categorizes them based on provided section names
* @param content - The PP3 file content as a string
* @param sectionNames - Array of section names to include
* @returns Object containing included sections, excluded sections, and section order
*/
export function splitPP3ContentBySections(content, sectionNames) {
const includedSections = [];
const excludedSections = [];
const { sections, sectionOrders } = splitContentBySections(content, (section, sectionName) => {
if (sectionNames.includes(sectionName)) {
includedSections.push(section);
}
else {
excludedSections.push(section);
}
});
return { sections, sectionOrders, includedSections, excludedSections };
}
/**
* Splits content into sections based on section headers in square brackets
* @param content - The content to split into sections
* @returns Object containing sections and their order
*/
export function splitContentIntoSections(content) {
return splitContentBySections(content);
}
//# sourceMappingURL=section-parser.js.map