From af764c5aa9c312b3c5a9ea156c5e82a31d268aef Mon Sep 17 00:00:00 2001 From: mdb Date: Mon, 12 Jul 2004 12:20:08 +0000 Subject: [PATCH] Added appendPath(). git-svn-id: https://samskivert.googlecode.com/svn/trunk@1461 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../src/java/com/samskivert/net/PathUtil.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/projects/samskivert/src/java/com/samskivert/net/PathUtil.java b/projects/samskivert/src/java/com/samskivert/net/PathUtil.java index e174250d..d9ead4a2 100644 --- a/projects/samskivert/src/java/com/samskivert/net/PathUtil.java +++ b/projects/samskivert/src/java/com/samskivert/net/PathUtil.java @@ -45,4 +45,27 @@ public class PathUtil return newComponent; } } + + /** + * Appends the supplied affix to the specified source path, ensuring + * that exactly one path separator (/ as we are dealing + * with URLs here not platform specific file-system paths) is used + * between the two. Note: this means that the affix will be + * made into a relative path regardless of whether or not it starts + * with a /. + */ + public static String appendPath (String source, String affix) + { + if (source.endsWith("/")) { + if (affix.startsWith("/")) { + return source + affix.substring(1); + } else { + return source + affix; + } + } else if (affix.startsWith("/")) { + return source + affix; + } else { + return source + "/" + affix; + } + } }