in curator-client/src/main/java/org/apache/curator/utils/ZKPaths.java [456:498]
private static void joinPath(StringBuilder path, String parent, String child) {
// Add parent piece, with no trailing slash.
if ((parent != null) && (parent.length() > 0)) {
if (parent.charAt(0) != PATH_SEPARATOR_CHAR) {
path.append(PATH_SEPARATOR_CHAR);
}
if (parent.charAt(parent.length() - 1) == PATH_SEPARATOR_CHAR) {
path.append(parent, 0, parent.length() - 1);
} else {
path.append(parent);
}
}
if ((child == null)
|| (child.length() == 0)
|| (child.length() == 1 && child.charAt(0) == PATH_SEPARATOR_CHAR)) {
// Special case, empty parent and child
if (path.length() == 0) {
path.append(PATH_SEPARATOR_CHAR);
}
return;
}
// Now add the separator between parent and child.
path.append(PATH_SEPARATOR_CHAR);
int childAppendBeginIndex;
if (child.charAt(0) == PATH_SEPARATOR_CHAR) {
childAppendBeginIndex = 1;
} else {
childAppendBeginIndex = 0;
}
int childAppendEndIndex;
if (child.charAt(child.length() - 1) == PATH_SEPARATOR_CHAR) {
childAppendEndIndex = child.length() - 1;
} else {
childAppendEndIndex = child.length();
}
// Finally, add the child.
path.append(child, childAppendBeginIndex, childAppendEndIndex);
}