Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.litesoft.core.typeutils;

public class Paths
{
    public static boolean endsWithSep( String pPath )
    {
        return (pPath != null) && Characters.isPathSep( pPath.charAt( pPath.length() - 1 ) );
    }

    public static int lastSepAt( String pPath )
    {
        if ( pPath != null )
        {
            for ( int at = pPath.length(); --at >= 0; )
            {
                if ( Characters.isPathSep( pPath.charAt( at ) ) )
                {
                    return at;
                }
            }
        }
        return -1;
    }

    public static String forwardSlash( String pPath )
    {
        return pPath.replace( '\\', '/' );
    }

    /**
     * Given path(s) that may be system dependent, create a path
     * that is converted to a system independent form (forward Slashes).
     * Note: Ignore null entries (null, or all nulls returns null).
     */
    public static String forwardSlashCombine( String... pPaths )
    {
        StringBuilder sb = null;
        if ( pPaths != null )
        {
            for ( String path : pPaths )
            {
                if ( path != null )
                {
                    if ( sb == null )
                    {
                        sb = new StringBuilder();
                    }
                    if ( path.length() != 0 )
                    {
                        String fsp = forwardSlash( path );
                        if ( sb.length() == 0 )
                        {
                            sb.append( fsp );
                        }
                        else
                        {
                            boolean pStartsWithSlash = (fsp.charAt( 0 ) == '/');
                            if ( sb.charAt( sb.length() - 1 ) == '/' )
                            {
                                sb.append( pStartsWithSlash ? fsp.substring( 1 ) : fsp );
                            }
                            else
                            {
                                if ( !pStartsWithSlash )
                                {
                                    sb.append( '/' );
                                }
                                sb.append( fsp );
                            }
                        }
                    }
                }
            }
        }
        return (sb == null) ? null : sb.toString();
    }

    public static String justTheLastName( String pPath )
    {
        pPath = "/\\" + pPath;
        return pPath.substring( Math.max( pPath.lastIndexOf( '/' ), pPath.lastIndexOf( '\\' ) ) + 1 );
    }
}

Commits for litesoft/trunk/DeviceDesktopTest/src/org/litesoft/core/typeutils/Paths.java

Diff revisions: vs.
Revision Author Commited Message
936 GeorgeS picture GeorgeS Sun 01 Jun, 2014 20:19:38 +0000

Language Support