resolveURL static method

dynamic resolveURL(
  1. dynamic url,
  2. String path
)

Implementation

static resolveURL(url, String path) {
  // Invalid URL
  // if ( typeof url != 'string' || url == '' ) return '';
  if (url is! String || url == '') return '';

  // Host Relative URL
  final reg1 = RegExp("^https?://", caseSensitive: false);
  if (reg1.hasMatch(path) && RegExp("^/", caseSensitive: false).hasMatch(url)) {
    final reg2 = RegExp("(^https?://[^/]+).*", caseSensitive: false);

    final matches = reg2.allMatches(path);

    for (var m in matches) {
      path = path.replaceFirst(m.group(0)!, m.group(1)!);
    }

    print("GLTFHelper.resolveURL todo debug  ");
    // path = path.replace( RegExp("(^https?:\/\/[^\/]+).*", caseSensitive: false), '$1' );

  }

  // Absolute URL http://,https://,//
  if (RegExp("^(https?:)?//", caseSensitive: false).hasMatch(url)) {
    return url;
  }

  // Data URI
  if (RegExp(r"^data:.*,.*$", caseSensitive: false).hasMatch(url)) return url;

  // Blob URL
  if (RegExp(r"^blob:.*$", caseSensitive: false).hasMatch(url)) return url;

  // Relative URL
  return path + url;
}