1
0
mirror of https://github.com/samba-team/samba.git synced 2025-11-20 08:23:50 +03:00

r8338: - added a substitute_var() js library function for doing hash driven

substitution of variables in strings

- the js provision script now correctly processes provision.ldif
This commit is contained in:
Andrew Tridgell
2005-07-12 02:36:07 +00:00
committed by Gerald (Jerry) Carter
parent 28c1a1f3c0
commit c2946003e0
2 changed files with 98 additions and 110 deletions

View File

@@ -50,3 +50,32 @@ function check_array_zero(a)
assert(a[i] == 0);
}
}
/*
substitute strings of the form ${NAME} in str, replacing
with substitutions from subobj
*/
function substitute_var(str, subobj)
{
var list = split("${", str);
var i;
for (i=1;i<list.length;i++) {
var list2 = split("}", list[i]);
if (list2.length < 2) {
return undefined;
}
var key = list2[0];
var val;
if (typeof(subobj[key]) == "undefined") {
val = "${" + key + "}";
} else if (typeof(subobj[key]) == "string") {
val = subobj[key];
} else {
var fn = subobj[key];
val = fn(key);
}
list2[0] = "" + val;
list[i] = join("", list2);
}
return join("", list);
}