X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=src%2Fclub%2Fwpia%2Fgigi%2Foutput%2Ftemplate%2FSprintfCommand.java;h=015fe6b6eca353c20d548a2af6c46c4d5c85882d;hp=6b40c8fd0ab49bd88b6f4c6f4dba4aca934b4dfc;hb=d71624703243c182beb0f946ebc582e0366a4686;hpb=bccd4cc0dba0f89aa045b113bac46eb8cc1dab4e diff --git a/src/club/wpia/gigi/output/template/SprintfCommand.java b/src/club/wpia/gigi/output/template/SprintfCommand.java index 6b40c8fd..015fe6b6 100644 --- a/src/club/wpia/gigi/output/template/SprintfCommand.java +++ b/src/club/wpia/gigi/output/template/SprintfCommand.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import club.wpia.gigi.Gigi; import club.wpia.gigi.localisation.Language; import club.wpia.gigi.util.HTMLEncoder; @@ -29,7 +30,7 @@ public final class SprintfCommand implements Translatable { * a string with {0},{1},.. as placeholders. * @param store * the data to put into the placeholders: ${var}, $!{var}, - * !'plain'. + * !'plain', !(/link). */ public SprintfCommand(String text, List store) { this.text = text; @@ -38,7 +39,7 @@ public final class SprintfCommand implements Translatable { private static final String VARIABLE = "\\$!?\\{[a-zA-Z0-9_-]+\\}"; - private static final Pattern processingInstruction = Pattern.compile("(" + VARIABLE + ")|(!'[^{}'\\$]*)'"); + private static final Pattern processingInstruction = Pattern.compile("(" + VARIABLE + ")|(?:(!'[^{}'\\$]*)')|(?:(!\\([^{})\\$]*)\\))"); /** * Creates a new SprintfCommand that is parsed as from template source. @@ -59,6 +60,8 @@ public final class SprintfCommand implements Translatable { var.add(group); } else if ((group = m.group(2)) != null) { var.add(group); + } else if ((group = m.group(3)) != null) { + var.add(group); } else { throw new Error("Regex is broken??"); } @@ -84,6 +87,16 @@ public final class SprintfCommand implements Translatable { Template.outputVar(out, l, vars, var.substring(3, var.length() - 1), true); } else if (var.startsWith("!'")) { out.print(var.substring(2)); + } else if (var.startsWith("!(")) { + String host = (String) vars.get(Gigi.LINK_HOST); + if (host == null) { + throw new Error("Unconfigured link-host while interpreting link-syntax."); + } + if (var.charAt(2) != '/') { + throw new Error("Need an absolute link for the link service."); + } + String link = "//" + host + var.substring(2); + out.print(""); } else if (var.startsWith("$")) { Template.outputVar(out, l, vars, var.substring(2, var.length() - 1), false); } else {