string property

String get string

Returns the normalized string representation for this HREF.

Implementation

String get string {
  if (href.isBlank) {
    return baseHref;
  }

  String resolved;
  try {
    Uri absoluteUri = Uri.parse(baseHref).resolve(href);
    String absoluteString = absoluteUri.toString(); // This is percent-decoded
    bool addSlash = !absoluteUri.hasScheme && !absoluteString.startsWith("/");
    resolved = ((addSlash) ? "/" : "") + absoluteString;
  } on Exception {
    if (href.startsWith("http://") || href.startsWith("https://")) {
      resolved = href;
    } else {
      resolved = baseHref.removeSuffix("/") + href.addPrefix("/");
    }
  }

  return Uri.decodeFull(resolved);
}