lemmur-app-android/lib/util/cleanup_url.dart

21 lines
480 B
Dart
Raw Normal View History

2021-04-06 10:56:21 +02:00
/// Returns a normalized host of a (maybe) url without a leading www.
String normalizeInstanceHost(String maybeUrl) {
try {
2021-04-06 10:56:21 +02:00
return urlHost(
maybeUrl.startsWith('https://') ? maybeUrl : 'https://$maybeUrl');
} on FormatException {
return '';
}
}
2021-01-27 20:53:09 +01:00
// Returns host of a url without a leading 'www.' if present
String urlHost(String url) {
final host = Uri.parse(url).host;
if (host.startsWith('www.')) {
return host.substring(4);
}
return host;
}