NamePieces parseName ( String name ) { NamePieces pieces = new NamePieces ( ) ; int dotpos = name . lastIndexOf ( ' ' ) ; int slashpos = name . lastIndexOf ( ' ' ) ; if ( slashpos < 0 && dotpos < 0 ) { pieces . name = name ; } else if ( slashpos >= 0 && dotpos < 0 ) { pieces . prefix = name . substring ( 0 , slashpos ) ; pieces . name = name . substring ( slashpos + 1 , name . length ( ) ) ; } else if ( slashpos < 0 && dotpos >= 0 ) { pieces . var = name . substring ( 0 , dotpos ) ; pieces . name = name . substring ( dotpos + 1 , name . length ( ) ) ; } else { //slashpos >= 0 && dotpos >= 0) if ( slashpos > dotpos ) { pieces . prefix = name . substring ( 0 , slashpos ) ; pieces . name = name . substring ( slashpos + 1 , name . length ( ) ) ; } else { //slashpos < dotpos) pieces . prefix = name . substring ( 0 , slashpos ) ; pieces . var = name . substring ( slashpos + 1 , dotpos ) ; pieces . name = name . substring ( dotpos + 1 , name . length ( ) ) ; } } // fixup if ( pieces . prefix != null && pieces . prefix . length ( ) == 0 ) pieces . prefix = null ; if ( pieces . var != null && pieces . var . length ( ) == 0 ) pieces . var = null ; if ( pieces . name . length ( ) == 0 ) pieces . name = null ; return pieces ; }
Utility to decompose a name