1 package org.apache.maven.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 import java.util.Arrays;
22 import java.util.List;
23
24 import org.codehaus.plexus.util.StringUtils;
25
26 /**
27 * @author <a href="mailto:bwalding@jakarta.org">Ben Walding</a>
28 * @version $Id: StringTool.java 517014 2007-03-11 21:15:50Z ltheussl $
29 * @todo move to org.apache.maven.util or make a jelly tag
30 */
31 public class StringTool
32 {
33
34 /**
35 * Splits a string at the last delimiter. If no delimiter is found,
36 * first element is the string, second element is empty string.
37 * @param s the string to be split
38 * @param delim the delimiter
39 * @return String[] a two element array, element 0 = string up to last delim (exclusive), element 1 = string past
40 * last delim (exclusive)
41 */
42 public List splitStringAtLastDelim( String s, String delim )
43 {
44 if ( s == null )
45 {
46 String[] result = { null, null };
47 return Arrays.asList( result );
48 }
49
50 int index = s.lastIndexOf( delim );
51
52 if ( index == -1 )
53 {
54 String[] result = { s, "" };
55 return Arrays.asList( result );
56 }
57 else
58 {
59 String[] result = { s.substring( 0, index ), s.substring( index + 1 ) };
60 return Arrays.asList( result );
61 }
62 }
63
64 /**
65 * <p>Removes all whitespace characters from the start and end of a String.</p>
66 *
67 * <p>This is similar to {@link #trim(String)} but removes whitespace.
68 * Whitespace is defined by {@link Character#isWhitespace(char)}.</p>
69 *
70 * @param s the String to remove characters from, may be null
71 * @return the trimmed String, <code>null</code> if null String input
72 */
73 public static String trim( String s )
74 {
75 return StringUtils.strip( s );
76 }
77 }