11cb0ef41Sopenharmony_ciexports.replaceDollarWithPercentPair = replaceDollarWithPercentPair 21cb0ef41Sopenharmony_ciexports.convertToSetCommand = convertToSetCommand 31cb0ef41Sopenharmony_ciexports.convertToSetCommands = convertToSetCommands 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cifunction convertToSetCommand (key, value) { 61cb0ef41Sopenharmony_ci var line = '' 71cb0ef41Sopenharmony_ci key = key || '' 81cb0ef41Sopenharmony_ci key = key.trim() 91cb0ef41Sopenharmony_ci value = value || '' 101cb0ef41Sopenharmony_ci value = value.trim() 111cb0ef41Sopenharmony_ci if (key && value && value.length > 0) { 121cb0ef41Sopenharmony_ci line = '@SET ' + key + '=' + replaceDollarWithPercentPair(value) + '\r\n' 131cb0ef41Sopenharmony_ci } 141cb0ef41Sopenharmony_ci return line 151cb0ef41Sopenharmony_ci} 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_cifunction extractVariableValuePairs (declarations) { 181cb0ef41Sopenharmony_ci var pairs = {} 191cb0ef41Sopenharmony_ci declarations.map(function (declaration) { 201cb0ef41Sopenharmony_ci var split = declaration.split('=') 211cb0ef41Sopenharmony_ci pairs[split[0]] = split[1] 221cb0ef41Sopenharmony_ci }) 231cb0ef41Sopenharmony_ci return pairs 241cb0ef41Sopenharmony_ci} 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_cifunction convertToSetCommands (variableString) { 271cb0ef41Sopenharmony_ci var variableValuePairs = extractVariableValuePairs(variableString.split(' ')) 281cb0ef41Sopenharmony_ci var variableDeclarationsAsBatch = '' 291cb0ef41Sopenharmony_ci Object.keys(variableValuePairs).forEach(function (key) { 301cb0ef41Sopenharmony_ci variableDeclarationsAsBatch += convertToSetCommand(key, variableValuePairs[key]) 311cb0ef41Sopenharmony_ci }) 321cb0ef41Sopenharmony_ci return variableDeclarationsAsBatch 331cb0ef41Sopenharmony_ci} 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_cifunction replaceDollarWithPercentPair (value) { 361cb0ef41Sopenharmony_ci var dollarExpressions = /\$\{?([^$@#?\- \t{}:]+)\}?/g 371cb0ef41Sopenharmony_ci var result = '' 381cb0ef41Sopenharmony_ci var startIndex = 0 391cb0ef41Sopenharmony_ci do { 401cb0ef41Sopenharmony_ci var match = dollarExpressions.exec(value) 411cb0ef41Sopenharmony_ci if (match) { 421cb0ef41Sopenharmony_ci var betweenMatches = value.substring(startIndex, match.index) || '' 431cb0ef41Sopenharmony_ci result += betweenMatches + '%' + match[1] + '%' 441cb0ef41Sopenharmony_ci startIndex = dollarExpressions.lastIndex 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci } while (dollarExpressions.lastIndex > 0) 471cb0ef41Sopenharmony_ci result += value.slice(startIndex) 481cb0ef41Sopenharmony_ci return result 491cb0ef41Sopenharmony_ci} 50