litesoft
Diff Revisions
822
vs
823
for /trunk/Java/core/Anywhere/src/org/litesoft/core/typeutils/Paths.java
|
@@ -26,4 +26,58 @@ |
26 |
26 |
|
{ |
27 |
27 |
|
return pPath.replace( '\\', '/' ); |
28 |
28 |
|
} |
|
29 |
+ |
|
|
30 |
+ |
/** |
|
31 |
+ |
* Given path(s) that may be system dependent, create a path |
|
32 |
+ |
* that is converted to a system independent form (forward Slashes). |
|
33 |
+ |
* Note: Ignore null entries (null, or all nulls returns null). |
|
34 |
+ |
*/ |
|
35 |
+ |
public static String forwardSlashCombine( String... pPaths ) |
|
36 |
+ |
{ |
|
37 |
+ |
StringBuilder sb = null; |
|
38 |
+ |
if ( pPaths != null ) |
|
39 |
+ |
{ |
|
40 |
+ |
for ( String path : pPaths ) |
|
41 |
+ |
{ |
|
42 |
+ |
if ( path != null ) |
|
43 |
+ |
{ |
|
44 |
+ |
if ( sb == null ) |
|
45 |
+ |
{ |
|
46 |
+ |
sb = new StringBuilder(); |
|
47 |
+ |
} |
|
48 |
+ |
if ( path.length() != 0 ) |
|
49 |
+ |
{ |
|
50 |
+ |
String fsp = forwardSlash( path ); |
|
51 |
+ |
if ( sb.length() == 0 ) |
|
52 |
+ |
{ |
|
53 |
+ |
sb.append( fsp ); |
|
54 |
+ |
} |
|
55 |
+ |
else |
|
56 |
+ |
{ |
|
57 |
+ |
boolean pStartsWithSlash = (fsp.charAt( 0 ) == '/'); |
|
58 |
+ |
if ( sb.charAt( sb.length() - 1 ) == '/' ) |
|
59 |
+ |
{ |
|
60 |
+ |
sb.append( pStartsWithSlash ? fsp.substring( 1 ) : fsp ); |
|
61 |
+ |
} |
|
62 |
+ |
else |
|
63 |
+ |
{ |
|
64 |
+ |
if ( !pStartsWithSlash ) |
|
65 |
+ |
{ |
|
66 |
+ |
sb.append( '/' ); |
|
67 |
+ |
} |
|
68 |
+ |
sb.append( fsp ); |
|
69 |
+ |
} |
|
70 |
+ |
} |
|
71 |
+ |
} |
|
72 |
+ |
} |
|
73 |
+ |
} |
|
74 |
+ |
} |
|
75 |
+ |
return (sb == null) ? null : sb.toString(); |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
public static String justTheLastName( String pPath ) |
|
79 |
+ |
{ |
|
80 |
+ |
pPath = "/\\" + pPath; |
|
81 |
+ |
return pPath.substring( Math.max( pPath.lastIndexOf( '/' ), pPath.lastIndexOf( '\\' ) ) + 1 ); |
|
82 |
+ |
} |
29 |
83 |
|
} |