replaceVars function
Implementation
String replaceVars(VarsCap vars) {
var str = vars.text;
var start = config.paramOutputPattern1;
var end = config.paramOutputPattern2;
if (_captureGoogleTranslateVar.hasMatch(str)) {
final wordset = <String>{};
final matches = _captureGoogleTranslateVar.allMatches(str);
for (var match in matches) {
wordset.add(str.substring(match.start, match.end));
}
// Replacing
var words = wordset.toList();
for (var i = 0; i < words.length; i++) {
var key0 = words[i];
var key = key0.replaceAll(_replaceAndLeaveDigitVar, '');
var value = vars.vars[key]!;
if (value.startsWith('@:')) {
/// If we resolve linked keys we play safe with the key.
if (config.resolveLinkedKeys) {
str = str.replaceAll(key0, '$value#');
} else {
str = str.replaceAll(key0, value);
}
} else {
//// special characters taken in account?
// value = value.replaceAll(r'$', '\\\$');
str = str.replaceAll(key0, '$start$value$end');
}
}
}
return str;
}