diff --git a/projects/samskivert/src/java/com/samskivert/net/PathUtil.java b/projects/samskivert/src/java/com/samskivert/net/PathUtil.java new file mode 100644 index 00000000..abc6a577 --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/net/PathUtil.java @@ -0,0 +1,28 @@ +// +// $Id: PathUtil.java,v 1.1 2001/03/04 07:33:29 mdb Exp $ + +package com.samskivert.util; + +/** + * Path related utility functions. + */ +public class PathUtil +{ + /** + * Replaces the final component in the supplied path with the + * specified new component. For example, if /foo/bar/baz + * was provided as the source path, baz would be replaced + * with the supplied new path component. If no slashes occur in the + * path, the entire path will be replaced. + */ + public static String replaceFinalComponent (String source, + String newComponent) + { + int sidx = source.lastIndexOf("/"); + if (sidx != -1) { + return source.substring(0, sidx+1) + newComponent; + } else { + return newComponent; + } + } +}