svn commit: r1733754 - /cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/ParamSaxBuffer.java

[email protected]
Newsgroups gmane.text.xml.cocoon.cvs
Message-ID <[email protected]>
Author: cdamioli
Date: Sat Mar  5 18:36:11 2016
New Revision: 1733754

URL: http://svn.apache.org/viewvc?rev=1733754&view=rev
Log:
COCOON-2350 Add a way to escape accolades in i18n messages

Modified:
    cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/ParamSaxBuffer.java

Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/ParamSaxBuffer.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/ParamSaxBuffer.java?rev=1733754&r1=1733753&r2=1733754&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/ParamSaxBuffer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/ParamSaxBuffer.java Sat Mar  5 18:36:11 2016
@@ -61,6 +61,7 @@ public class ParamSaxBuffer extends SaxB
     /**
      * Parses text and extracts <code>{name}</code> parameters for later
      * substitution.
+     * '{' is escaped with a preceding '\'.
      */
     public void characters(char ch[], int start, int length) throws SAXException {
 
@@ -77,7 +78,23 @@ public class ParamSaxBuffer extends SaxB
 
         final int end = start + length;
         for (int i = start; i < end; i++) {
-            if (ch[i] == '{') {
+            if (ch[i] == '\\') {
+                if (i + 1 == end) {
+                    // if '\' is the last char, flush chars and let's wait to see if a '{' or '\' will come next
+                    addBit(new Characters(ch, start, i - start));
+                    previous_ch = new char[]{ch[i]};
+                    return;
+                }
+                if (ch[i + 1] == '{' || ch[i + 1] == '\\') {
+                    // Encountered "\{" or "\\", meaning that the next char should be escaped
+                    addBit(new Characters(ch, start, i - start));
+                    addBit(new Characters(new char[]{ch[i + 1]}, 0, 1));
+                    i++;
+                    start = i + 1;
+                    continue;
+                }
+            }
+            else if (ch[i] == '{') {
                 // Send any collected characters so far
                 if (i > start) {
                     addBit(new Characters(ch, start, i - start));
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.