1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.rendering.wikimodel.xwiki.xwiki20

File XWikiScannerUtil.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

24
35
2
1
99
61
15
0.43
17.5
2
7.5

Classes

Class Line # Actions
XWikiScannerUtil 26 35 0% 15 6
0.9016393490.2%
 

Contributing tests

This file is covered by 48 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.wikimodel.xwiki.xwiki20;
21   
22    /**
23    * @version $Id: baf1894b3da110be4a300f0135bd2e96a0757ef9 $
24    * @since 4.0M1
25    */
 
26    public class XWikiScannerUtil
27    {
28    public static final char ESCAPECHAR = '~';
29   
30    /**
31    * To have }}} or {{{ inside inline block we need to escape it in some
32    * condition. This method remove this escaping to send the correct text to
33    * the event.
34    */
 
35  8829 toggle public static String unescapeVerbatim(String content)
36    {
37  8829 StringBuffer unescapedContent = new StringBuffer();
38   
39  8829 boolean escaped = false;
40  8829 char[] buff = content.toCharArray();
41  672014 for (int i = 0; i < buff.length; ++i) {
42  663185 if (!escaped) {
43  662898 if (buff[i] == '~') {
44  287 escaped = true;
45  287 continue;
46    }
47    } else {
48  ? if (i < (i = matchVerbatimSyntax(buff, i, '{'))) {
49  17 unescapedContent.append("{{{");
50  17 escaped = false;
51  17 continue;
52  ? } else if (i < (i = matchVerbatimSyntax(buff, i, '}'))) {
53  19 unescapedContent.append("}}}");
54  19 escaped = false;
55  19 continue;
56    } else {
57  251 unescapedContent.append('~');
58    }
59   
60  251 escaped = false;
61    }
62   
63  662862 unescapedContent.append(buff[i]);
64    }
65   
66  8829 return unescapedContent.toString();
67    }
68   
 
69  557 toggle private static int matchVerbatimSyntax(char buff[], int currentIndex,
70    char syntax)
71    {
72   
73  557 int i = currentIndex;
74  557 boolean escaped = true;
75  661 for (int j = 0; i < buff.length && j < 3; ++i) {
76  661 if (!escaped) {
77  72 if (buff[i] == syntax) {
78  40 if (++j == 3) {
79  20 return i;
80    }
81  32 } else if (buff[i] == '~') {
82  32 escaped = true;
83    }
84    } else {
85  589 if (buff[i] == syntax) {
86  68 if (++j == 3) {
87  16 return i;
88    }
89    } else {
90  521 break;
91    }
92   
93  52 escaped = false;
94    }
95    }
96   
97  521 return currentIndex;
98    }
99    }