案例一
说明:源码来自spark ConfigReader类1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23private object ConfigReader {
private val REF_RE = "\\$\\{(?:(\\w+?):)?(\\S+?)\\}".r
}
private def substitute(input: String, usedRefs: Set[String]): String = {
if (input != null) {
ConfigReader.REF_RE.replaceAllIn(input, { m =>
val prefix = m.group(1)
val name = m.group(2)
val ref = if (prefix == null) name else s"$prefix:$name"
require(!usedRefs.contains(ref), s"Circular reference in $input: $ref")
val replacement = bindings.get(prefix)
.flatMap(getOrDefault(_, name))
.map { v => substitute(v, usedRefs + ref) }
.getOrElse(m.matched)
Regex.quoteReplacement(replacement)
})
} else {
input
}
}