joinURL function

String joinURL(
  1. String parent,
  2. String child, {
  3. bool removeParentLastRoute = false,
})

Implementation

String joinURL(
  final String parent,
  final String child, {
  final bool removeParentLastRoute = false,
}) {
  final List<String> sParent = parent.split('/');
  final List<String> sChild = child.split('/');

  if (removeParentLastRoute) sParent.removeLast();

  bool done = false;
  while (!done) {
    if (sChild[0] == '.') {
      sChild.removeAt(0);
    } else if (sChild[0] == '..') {
      sParent.removeLast();
      sChild.removeAt(0);
    } else {
      done = true;
    }
  }

  if (sParent.last != '') sParent.add('');
  if (sChild.first == '') sChild.removeAt(0);

  return sParent.join('/') + sChild.join('/');
}