LSLApiConfig.fromString constructor
LSLApiConfig.fromString(
- String iniContent
Parse a configuration string in INI format
Implementation
factory LSLApiConfig.fromString(String iniContent) {
final config = LSLApiConfig();
// Parse the INI content and populate the configuration
final lines = iniContent.split('\n');
ConfigSection? currentSection;
for (var line in lines) {
line = line.trim();
// Skip empty lines and comments
if (line.isEmpty || line.startsWith(';')) continue;
// Check for section header
if (line.startsWith('[') && line.endsWith(']')) {
final sectionName = line.substring(1, line.length - 1).toLowerCase();
currentSection = ConfigSection.values.firstWhereOrNull(
(s) => s.name.toLowerCase() == sectionName,
);
continue;
}
// Skip if no valid section found
if (currentSection == null) continue;
// Parse key-value pairs
final parts = line.split('=');
if (parts.length < 2) continue;
final key = parts[0].trim();
final value = parts.sublist(1).join('=').trim();
config._setValue(currentSection, key, value);
}
return config;
}