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

File StringUtils.java

 

Coverage histogram

../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

8
17
2
1
86
33
6
0.35
8.5
2
3

Classes

Class Line # Actions
StringUtils 32 17 0% 6 0
1.0100%
 

Contributing tests

No tests hitting this source file were found.

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.text;
21   
22    import org.xwiki.stability.Unstable;
23   
24    /**
25    * Extends {@link org.apache.commons.lang3.StringUtils} with some more useful tools. Note that the reason we're
26    * extending Commons Lang instead of creating a separate class is because we're using this class as a Velocity tool
27    * and we want to offer a single binding to users.
28    *
29    * @version $Id: cca841aa005c00fe3a5f266a84350ec4fc6e99fb $
30    * @since 6.2
31    */
 
32    public class StringUtils extends org.apache.commons.lang3.StringUtils
33    {
34    /**
35    * An attempt to make doubling a character (usually for escaping purposes) as fast as it can be. A lot faster than
36    * the usual <code>mystring.replace("a", "aa")</code> for example.
37    *
38    * @param str the string to modify
39    * @param c the character to double
40    * @return the modified string
41    */
 
42  7 toggle public static String doubleChar(final String str, final char c)
43    {
44  7 if (isEmpty(str)) {
45  2 return str;
46    }
47   
48  5 int start = 0;
49  5 int end = str.indexOf(c, start);
50  5 if (end == INDEX_NOT_FOUND) {
51  1 return str;
52    }
53   
54  4 final StringBuilder buf = new StringBuilder(str.length() + 1);
55   
56  4 do {
57  7 end += 1;
58  7 buf.append(str.substring(start, end)).append(c);
59   
60  7 start = end;
61  7 end = str.indexOf(c, start);
62  7 } while (end != INDEX_NOT_FOUND);
63   
64  4 buf.append(str.substring(start));
65   
66  4 return buf.toString();
67    }
68   
69    /**
70    * Removes all non alpha numerical characters from the passed text. First tries to convert diacritics to their
71    * alpha numeric representation.
72    *
73    * @param text the text to convert
74    * @return the alpha numeric equivalent
75    * @since 10.6RC1
76    */
 
77  40506 toggle @Unstable
78    public static String toAlphaNumeric(String text)
79    {
80  40506 if (isEmpty(text)) {
81  28 return text;
82    }
83   
84  40478 return stripAccents(text).replaceAll("[^a-zA-Z0-9]", "");
85    }
86    }