Expands Xcode-style $(VARIABLES) in string per the expansions dict. In some rare cases, it is appropriate to expand Xcode variables when a project file is generated. For any substring $(VAR) in string, if VAR is a key in the expansions dict, $(VAR) will be replaced with expansions[VAR]
(string, expansions)
| 562 | |
| 563 | |
| 564 | def ExpandXcodeVariables(string, expansions): |
| 565 | """Expands Xcode-style $(VARIABLES) in string per the expansions dict. |
| 566 | |
| 567 | In some rare cases, it is appropriate to expand Xcode variables when a |
| 568 | project file is generated. For any substring $(VAR) in string, if VAR is a |
| 569 | key in the expansions dict, $(VAR) will be replaced with expansions[VAR]. |
| 570 | Any $(VAR) substring in string for which VAR is not a key in the expansions |
| 571 | dict will remain in the returned string. |
| 572 | """ |
| 573 | |
| 574 | matches = _xcode_variable_re.findall(string) |
| 575 | if matches is None: |
| 576 | return string |
| 577 | |
| 578 | matches.reverse() |
| 579 | for match in matches: |
| 580 | (to_replace, variable) = match |
| 581 | if variable not in expansions: |
| 582 | continue |
| 583 | |
| 584 | replacement = expansions[variable] |
| 585 | string = re.sub(re.escape(to_replace), replacement, string) |
| 586 | |
| 587 | return string |
| 588 | |
| 589 | |
| 590 | _xcode_define_re = re.compile(r"([\\\"\' ])") |
no test coverage detected