joinWithSlash method

String joinWithSlash (String start, String end)

Given 2 parts of a url, join them with a slash if needed.

Implementation

static String joinWithSlash(String start, String end) {
  if (start.isEmpty) {
    return end;
  }
  if (end.isEmpty) {
    return start;
  }
  var slashes = 0;
  if (start.endsWith('/')) {
    slashes++;
  }
  if (end.startsWith('/')) {
    slashes++;
  }
  if (slashes == 2) {
    return start + end.substring(1);
  }
  if (slashes == 1) {
    return start + end;
  }
  return '$start/$end';
}