processDefFileText function
String
processDefFileText(})
Implementation
String processDefFileText(
String fileText,
{
String baseFolderPath = '',
String filePath = '',
String Function( String, [String] )? readTextFileFunction = readTextFile,
bool hasImportCommands = true,
String Function( String )? getImportedPathFunction = getImportedPath,
List<String> Function( String )? getImportedFilePathArrayFunction = getImportedFilePathArray
}
)
{
if ( hasImportCommands )
{
var folderPath = filePath.substring( 0, filePath.lastIndexOf( '/' ) + 1 );
var lineArray = fileText.split( '\n' );
for ( var lineIndex = 0;
lineIndex < lineArray.length;
++lineIndex )
{
var line = lineArray[ lineIndex ];
var trimmedLine = line.trim();
var importedFileFilter = getImportedPathFunction!( trimmedLine );
if ( importedFileFilter.isNotEmpty )
{
lineArray.removeAt( lineIndex );
var importedFilePathArray = getImportedFilePathArrayFunction!( folderPath + importedFileFilter );
for ( var importedFilePath in importedFilePathArray )
{
var importedFileText =
readDefFileText(
importedFilePath,
baseFolderPath: baseFolderPath,
readTextFileFunction: readTextFileFunction,
hasImportCommands: hasImportCommands,
getImportedPathFunction: getImportedPathFunction,
getImportedFilePathArrayFunction: getImportedFilePathArrayFunction
);
var indentation = line.substring( 0, line.length - line.trimLeft().length );
var indentedLineArray = importedFileText.split( '\n' );
for ( var indentedLineIndex = 0;
indentedLineIndex < indentedLineArray.length;
++indentedLineIndex )
{
indentedLineArray[ indentedLineIndex ] = indentation + indentedLineArray[ indentedLineIndex ];
}
lineArray.insertAll( lineIndex, indentedLineArray );
lineIndex += indentedLineArray.length;
}
--lineIndex;
}
}
fileText = lineArray.join( '\n' );
}
return fileText;
}