Skip to content

Commit

Permalink
Wrap try-finally
Browse files Browse the repository at this point in the history
  • Loading branch information
rk0cc committed Jan 10, 2024
1 parent 8a31aa9 commit 9feea49
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 168 deletions.
222 changes: 111 additions & 111 deletions model/lib/src/parser/open_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,123 +29,123 @@ final class OpenGraphPropertyParser extends MetaPropertyParser {
final VideoInfoParser vidParser = VideoInfoParser();
final AudioInfoParser audParser = AudioInfoParser();

for (PropertyPair metaTag in propertyPair) {
var (property, content) = metaTag;
try {
for (var (property, content) in propertyPair) {
switch (property) {
case "og:title":
assigner.title = content;
break;
case "og:url":
assigner.url = Uri.tryParse(content);
break;
case "og:description":
assigner.description = content;
break;
case "og:site_name":
assigner.siteName = content;
break;
case "og:image":
case "og:imagae:url":
if (imgParser.isInitalized) {
assigner.images.add(imgParser.compile());
imgParser.reset();
} else {
imgParser.markInitalized();
}

switch (property) {
case "og:title":
assigner.title = content;
break;
case "og:url":
assigner.url = Uri.tryParse(content);
break;
case "og:description":
assigner.description = content;
break;
case "og:site_name":
assigner.siteName = content;
break;
case "og:image":
case "og:imagae:url":
if (imgParser.isInitalized) {
assigner.images.add(imgParser.compile());
imgParser.reset();
} else {
imgParser.markInitalized();
}
imgParser.url = Uri.tryParse(content);
break;
case "og:image:secure_url":
if (imgParser.isInitalized) {
imgParser.secureUrl = Uri.tryParse(content);
}
break;
case "og:image:type":
if (imgParser.isInitalized) {
imgParser.type = content;
}
break;
case "og:image:width":
if (imgParser.isInitalized) {
imgParser.width = double.tryParse(content);
}
break;
case "og:image:height":
if (imgParser.isInitalized) {
imgParser.height = double.tryParse(content);
}
break;
case "og:image:alt":
if (imgParser.isInitalized) {
imgParser.alt = content;
}
break;
case "og:video":
case "og:video:url":
if (vidParser.isInitalized) {
assigner.videos.add(vidParser.compile());
vidParser.reset();
} else {
vidParser.markInitalized();
}

imgParser.url = Uri.tryParse(content);
break;
case "og:image:secure_url":
if (imgParser.isInitalized) {
imgParser.secureUrl = Uri.tryParse(content);
}
break;
case "og:image:type":
if (imgParser.isInitalized) {
imgParser.type = content;
}
break;
case "og:image:width":
if (imgParser.isInitalized) {
imgParser.width = double.tryParse(content);
}
break;
case "og:image:height":
if (imgParser.isInitalized) {
imgParser.height = double.tryParse(content);
}
break;
case "og:image:alt":
if (imgParser.isInitalized) {
imgParser.alt = content;
}
break;
case "og:video":
case "og:video:url":
if (vidParser.isInitalized) {
assigner.videos.add(vidParser.compile());
vidParser.reset();
} else {
vidParser.markInitalized();
}
vidParser.url = Uri.tryParse(content);
break;
case "og:video:secure_url":
if (vidParser.isInitalized) {
vidParser.secureUrl = Uri.tryParse(content);
}
break;
case "og:video:type":
if (vidParser.isInitalized) {
vidParser.type = content;
}
break;
case "og:video:width":
if (vidParser.isInitalized) {
vidParser.width = double.tryParse(content);
}
break;
case "og:video:height":
if (vidParser.isInitalized) {
vidParser.height = double.tryParse(content);
}
break;
case "og:audio":
case "og:audio:url":
if (audParser.isInitalized) {
assigner.audios.add(audParser.compile());
audParser.reset();
} else {
audParser.markInitalized();
}

vidParser.url = Uri.tryParse(content);
break;
case "og:video:secure_url":
if (vidParser.isInitalized) {
vidParser.secureUrl = Uri.tryParse(content);
}
break;
case "og:video:type":
if (vidParser.isInitalized) {
vidParser.type = content;
}
break;
case "og:video:width":
if (vidParser.isInitalized) {
vidParser.width = double.tryParse(content);
}
break;
case "og:video:height":
if (vidParser.isInitalized) {
vidParser.height = double.tryParse(content);
}
break;
case "og:audio":
case "og:audio:url":
if (audParser.isInitalized) {
assigner.audios.add(audParser.compile());
audParser.reset();
} else {
audParser.markInitalized();
}

audParser.url = Uri.tryParse(content);
break;
case "og:audio:secure_url":
if (audParser.isInitalized) {
audParser.secureUrl = Uri.tryParse(content);
}
break;
case "og:audio:type":
if (audParser.isInitalized) {
audParser.type = content;
}
break;
audParser.url = Uri.tryParse(content);
break;
case "og:audio:secure_url":
if (audParser.isInitalized) {
audParser.secureUrl = Uri.tryParse(content);
}
break;
case "og:audio:type":
if (audParser.isInitalized) {
audParser.type = content;
}
break;
}
}
} finally {
if (imgParser.url != null) {
assigner.images.add(imgParser.compile());
}
}

if (imgParser.url != null) {
assigner.images.add(imgParser.compile());
}

if (vidParser.url != null) {
assigner.videos.add(vidParser.compile());
}
if (vidParser.url != null) {
assigner.videos.add(vidParser.compile());
}

if (audParser.url != null) {
assigner.audios.add(audParser.compile());
if (audParser.url != null) {
assigner.audios.add(audParser.compile());
}
}
}
}
114 changes: 57 additions & 57 deletions model/lib/src/parser/twitter_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,67 +40,67 @@ final class TwitterCardPropertyParser extends MetaPropertyParser {
final ImageInfoParser imgParser = ImageInfoParser();
final VideoInfoParser vidParser = VideoInfoParser();

for (PropertyPair metaTag in propertyPair) {
var (property, value) = metaTag;
try {
for (var (property, value) in propertyPair) {
switch (property) {
case "twitter:site":
assigner.url ??= twitterSite.resolve("/${value.substring(1)}");
break;
case "twitter:site:id":
assigner.url ??= twitterSite.resolve("/i/user/$value");
break;
case "twitter:description":
assigner.description = value;
break;
case "twitter:title":
assigner.title = value;
break;
case "twitter:image":
if (imgParser.isInitalized) {
assigner.images.add(imgParser.compile());
imgParser.reset();
} else {
imgParser.markInitalized();
}

switch (property) {
case "twitter:site":
assigner.url ??= twitterSite.resolve("/${value.substring(1)}");
break;
case "twitter:site:id":
assigner.url ??= twitterSite.resolve("/i/user/$value");
break;
case "twitter:description":
assigner.description = value;
break;
case "twitter:title":
assigner.title = value;
break;
case "twitter:image":
if (imgParser.isInitalized) {
assigner.images.add(imgParser.compile());
imgParser.reset();
} else {
imgParser.markInitalized();
}
imgParser.url = Uri.tryParse(value);
break;
case "twitter:image:alt":
imgParser.alt = value;
break;
case "twitter:player":
if (vidParser.isInitalized) {
assigner.videos.add(vidParser.compile());
vidParser.reset();
} else {
vidParser.markInitalized();
}

imgParser.url = Uri.tryParse(value);
break;
case "twitter:image:alt":
imgParser.alt = value;
break;
case "twitter:player":
if (vidParser.isInitalized) {
assigner.videos.add(vidParser.compile());
vidParser.reset();
} else {
vidParser.markInitalized();
}

vidParser.url = Uri.tryParse(value);
break;
case "twitter:player:width":
vidParser.width = double.tryParse(value);
break;
case "twitter:player:height":
vidParser.height = double.tryParse(value);
break;
case "twitter:player:stream":
Uri? resolvedStream = Uri.tryParse(value);
if (resolvedStream != null && vidParser.url != null) {
// Uses raw file if provided instead of relying iframe.
vidParser.url = resolvedStream;
}
break;
vidParser.url = Uri.tryParse(value);
break;
case "twitter:player:width":
vidParser.width = double.tryParse(value);
break;
case "twitter:player:height":
vidParser.height = double.tryParse(value);
break;
case "twitter:player:stream":
Uri? resolvedStream = Uri.tryParse(value);
if (resolvedStream != null && vidParser.url != null) {
// Uses raw file if provided instead of relying iframe.
vidParser.url = resolvedStream;
}
break;
}
}
} finally {
if (imgParser.url != null) {
assigner.images.add(imgParser.compile());
}
}

if (imgParser.url != null) {
assigner.images.add(imgParser.compile());
}

if (vidParser.url != null) {
assigner.videos.add(vidParser.compile());
if (vidParser.url != null) {
assigner.videos.add(vidParser.compile());
}
}
}
}

0 comments on commit 9feea49

Please sign in to comment.