This is an automated email from the ASF dual-hosted git repository. ddekany pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/freemarker-docgen.git
commit e79b2ebd4bf7d08eecb4b4add2d29b744de264dd Author: ddekany <[email protected]> AuthorDate: Fri Nov 13 22:38:37 2020 +0100 Allow raw string literals in docgen tags. Use multi-line regexp parameters in docgen.insertFile. --- .../core/PrintTextWithDocgenSubstitutionsDirective.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/PrintTextWithDocgenSubstitutionsDirective.java b/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/PrintTextWithDocgenSubstitutionsDirective.java index 628e62a..c8110f0 100644 --- a/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/PrintTextWithDocgenSubstitutionsDirective.java +++ b/freemarker-docgen-core/src/main/java/org/freemarker/docgen/core/PrintTextWithDocgenSubstitutionsDirective.java @@ -299,7 +299,7 @@ public class PrintTextWithDocgenSubstitutionsDirective implements TemplateDirect } Pattern from; try { - from = Pattern.compile(fromArgCleaned); + from = Pattern.compile(fromArgCleaned, Pattern.MULTILINE); } catch (PatternSyntaxException e) { throw newErrorInDocgenTag("Invalid regular expression: " + fromArgCleaned); } @@ -336,7 +336,7 @@ public class PrintTextWithDocgenSubstitutionsDirective implements TemplateDirect if (toStr != null) { Pattern to; try { - to = Pattern.compile(toStr); + to = Pattern.compile(toStr, Pattern.MULTILINE); } catch (PatternSyntaxException e) { throw newErrorInDocgenTag("Invalid regular expression: " + toStr); } @@ -441,15 +441,22 @@ public class PrintTextWithDocgenSubstitutionsDirective implements TemplateDirect private String fetchOptionalString() throws TemplateException { char quoteChar = charAt(cursor); + boolean rawString = quoteChar == 'r'; + if (rawString) { + if (cursor + 1 < text.length()) { + quoteChar = charAt(cursor + 1); + } + } if (quoteChar != '"' && quoteChar != '\'') { return null; } - cursor++; + cursor += rawString ? 2 : 1; int stringStartIdx = cursor; while (cursor < text.length() && charAt(cursor) != quoteChar) { - if (charAt(cursor) == '\\') { + if (!rawString && charAt(cursor) == '\\') { throw new DocgenSubstitutionTemplateException( - "Backslash is currently not supported in string literal in Docgen tags.", env); + "Backslash is currently not supported in string literal in Docgen tags, " + + "except in raw strings (like r\"regular\\s+expression\").", env); } cursor++; }
