1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package gov.nasa.pds.tools.util;
17
18 /***
19 * @author pramirez
20 * @version $Revision$
21 *
22 */
23 public class Utility {
24
25 public static String stripWhitespace(String value) {
26 return filterString(stripNewLines(value));
27 }
28
29 public static String stripNewLines(String value) {
30 String filteredValue = value;
31
32
33 filteredValue = filteredValue.replaceAll("-" + System.getProperty("line.separator"), "");
34
35 filteredValue = filteredValue.replaceAll(System.getProperty("line.separator"), " ");
36 return filteredValue;
37 }
38
39 public static String filterString(String value) {
40 String filteredValue = value;
41
42 filteredValue = filteredValue.replaceAll("_", " ");
43
44 filteredValue = filteredValue.replaceAll("//s+", " ");
45
46 filteredValue = filteredValue.trim();
47 return filteredValue;
48 }
49
50 public static String trimString(String value, int length) {
51 String trimmedString = value;
52
53 if (trimmedString.length() > length*3)
54 trimmedString = trimmedString.substring(0, length*3);
55 trimmedString = stripNewLines(trimmedString);
56 trimmedString = filterString(trimmedString);
57 if (trimmedString.length() > length)
58 trimmedString = trimmedString.substring(0, length-1);
59
60 return trimmedString;
61 }
62 }