urlJoin function

String urlJoin(
  1. List<String?> args
)

Merges the given list argument (the beginning of the URL), joining it so that the slash (/) symbol is correctly included.

Implementation

String urlJoin(List<String?> args) {
  if (args.isEmpty) {
    return '';
  }

  String urlResult = '';
  int joinCount = 0;

  for (var arg in args) {
    if (arg != null) {
      if (joinCount == 0 ||
          arg.startsWith('/') ||
          arg.startsWith('?') ||
          arg.startsWith('&')) {
        urlResult += arg;
      } else {
        urlResult += '/$arg';
      }
      joinCount += 1;
    }
  }

  return urlResult.replaceAll(RegExp(r'/$'), '');
}