Coding and capturing long / multi-line strings
Closed this issue · 0 comments
PR #15 addresses only one of two use case I have.
Another use case which is more difficult to solve is translations of long or multi-line strings e.g.:
Example 1.
__("Part 1 of a long string.\n" .
"Part 2 of a long string.")
You could e,g. include the opening and closing quotations, and then do eval("return " . $match . ";")
which will work on the above example, but (obviously) use of eval
is potentially dangerous.
Note: In the above example we could have coded it (inconsistently but for good reasons) in a way which would break #15:
__("Part 1 of a 'long' string.\n" .
'Part 2 of a "long" string.')
I guess we could probably code this into a regex \(\s*(?:*'(.*)'|"(.*)")(?:\s*\.\s*(?:*'(.*)'|"(.*)"))*\s*\)
. See https://www.phpliveregex.com/p/FQQ for a non-working example (which doesn't handle (say) 3 or more lines - but we can probably make this work somehow).
Example 2.
__(<<<XYZ
Line 1 of a multi-line string.
Line 2 of a multi-line string.
XYZ);
(Obviously) this is difficult to do a regex for, and performance is likely to be impossibly slow if we don't use regex. So this form is probably not sensible to support.