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:
committed by
Gerald (Jerry) Carter
parent
28c1a1f3c0
commit
c2946003e0
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user