After we added support for parentheses in variable names in write.report(), it quickly became apparent that people also want to put parentheses into units. Since the most general case with parentheses in the variable name and the unit is actually not properly defined, we can only support balanced parentheses in the unit, i.e. as many opening as closing parentheses.
To support this, I had to resort to perl-compatible regular expressions with subroutines. I added a lot of comments in the hope that whoever has to touch this next has a chance to understand the regex.
After we added support for parentheses in variable names in
write.report()
, it quickly became apparent that people also want to put parentheses into units. Since the most general case with parentheses in the variable name and the unit is actually not properly defined, we can only support balanced parentheses in the unit, i.e. as many opening as closing parentheses.To support this, I had to resort to perl-compatible regular expressions with subroutines. I added a lot of comments in the hope that whoever has to touch this next has a chance to understand the regex.