1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.wikimodel.xwiki.xwiki20

File XWikiScannerUtil.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% 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  159 toggle public static String unescapeVerbatim(String content)
36    {
37  159 StringBuffer unescapedContent = new StringBuffer();
38   
39  159 boolean escaped = false;
40  159 char[] buff = content.toCharArray();
41  1629 for (int i = 0; i < buff.length; ++i) {
42  1470 if (!escaped) {
43  1429 if (buff[i] == '~') {
44  41 escaped = true;
45  41 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  5 unescapedContent.append('~');
58    }
59   
60  5 escaped = false;
61    }
62   
63  1393 unescapedContent.append(buff[i]);
64    }
65   
66  159 return unescapedContent.toString();
67    }
68   
 
69  65 toggle private static int matchVerbatimSyntax(char buff[], int currentIndex,
70    char syntax)
71    {
72   
73  65 int i = currentIndex;
74  65 boolean escaped = true;
75  169 for (int j = 0; i < buff.length && j < 3; ++i) {
76  169 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  97 if (buff[i] == syntax) {
86  68 if (++j == 3) {
87  16 return i;
88    }
89    } else {
90  29 break;
91    }
92   
93  52 escaped = false;
94    }
95    }
96   
97  29 return currentIndex;
98    }
99    }