parseKeyValuePairs function

Map<String, String> parseKeyValuePairs(
  1. String s,
  2. Set<String> targetKeys
)

Implementation

Map<String, String> parseKeyValuePairs(String s, Set<String> targetKeys) {
  final result = <String, String>{};
  final pairs = s.split(';');
  for (final pair in pairs) {
    final index = pair.indexOf(':');
    if (index < 0) {
      continue;
    }
    final key = pair.substring(0, index).trim();
    if (targetKeys.contains(key)) {
      result[key] = pair.substring(index + 1).trim();
    }
  }

  return result;
}