]> WPIA git - gigi.git/commitdiff
ADD: extend table syntax (sprintf string literals):
authorFelix Dörre <felix@dogcraft.de>
Fri, 19 Sep 2014 23:00:38 +0000 (01:00 +0200)
committerFelix Dörre <felix@dogcraft.de>
Fri, 19 Sep 2014 23:00:38 +0000 (01:00 +0200)
Example: <?=s,"<a href='#'>wiki</a>",See also in the %s.?>

doc/TemplateSyntax.txt
src/org/cacert/gigi/output/template/SprintfCommand.java
src/org/cacert/gigi/output/template/Template.java

index 9309f5e21808521681eeed194a838296af6449ac..47b36e905c3d70eeb55b6afd4a732fb3c0e34924 100644 (file)
@@ -11,6 +11,7 @@ A template is constructed from a charstream. Everything that is not in "<?" to "
 
 - <?=$!variablename?> will output the variable "variablename" but not HTML-escaped
 - <?=s,$!variablename,My %s text?> will insert the variable "variablename" into the translated text but not HTML-escaped
+- <?=s,"some data",My %s text?> will insert "some data" into the translated text literally (not HTML-escaped)
   
 - <? if($variable) { ?>
   Output/execute the text until "<? } ?>" only if $variable not null or Boolean.FALSE.
index 9cafef4787f58fd9f7451cdf1ceae85e455e09db..0275219b983366b1781e579260ab48f0d602233c 100644 (file)
@@ -28,6 +28,8 @@ public final class SprintfCommand implements Outputable {
             String var = myvars[j - 1];
             if (var.startsWith("$!")) {
                 Template.outputVar(out, l, vars, myvars[j - 1].substring(2), true);
+            } else if (var.startsWith("\"")) {
+                out.print(var.substring(1));
             } else {
                 Template.outputVar(out, l, vars, myvars[j - 1].substring(1), false);
             }
index ac59f3135ef75a11639710a81983be75ab990c53..69f17bda11db9cf6774e74e1f146aa6c0af2d88e 100644 (file)
@@ -121,9 +121,15 @@ public class Template implements Outputable {
         } else if (s2.startsWith("=s,")) {
             String command = s2.substring(3);
             final LinkedList<String> store = new LinkedList<String>();
-            while (command.startsWith("$")) {
-                int idx = command.indexOf(",");
-                store.add(command.substring(0, idx));
+            while (command.startsWith("$") || command.startsWith("\"")) {
+                int idx;
+                if (command.startsWith("\"")) {
+                    idx = command.indexOf("\"", 1) + 1;
+                    store.add(command.substring(0, idx - 1));
+                } else {
+                    idx = command.indexOf(",");
+                    store.add(command.substring(0, idx));
+                }
                 command = command.substring(idx + 1);
             }
             final String text = command;