From 6d27996ac448407956b2a8145ad905d23f217622 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 26 Mar 2022 20:03:27 +0100 Subject: [PATCH] Improve code of getStringResultFromRegexArray methods in Utils --- .../schabi/newpipe/extractor/utils/Utils.java | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java index 1cec52c5..ed4555ef 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java @@ -391,22 +391,19 @@ public final class Utils { @Nonnull final String[] regexes, final int group) throws Parser.RegexException { - String result = null; for (final String regex : regexes) { try { - result = Parser.matchGroup(regex, input, group); + final String result = Parser.matchGroup(regex, input, group); if (result != null) { - // Continue if the result is null - break; + return result; } + + // Continue if the result is null } catch (final Parser.RegexException ignored) { } } - if (result == null) { - throw new Parser.RegexException("No regex matched the input on group " + group); - } - return result; + throw new Parser.RegexException("No regex matched the input on group " + group); } /** @@ -425,21 +422,18 @@ public final class Utils { @Nonnull final Pattern[] regexes, final int group) throws Parser.RegexException { - String result = null; for (final Pattern regex : regexes) { try { - result = Parser.matchGroup(regex, input, group); + final String result = Parser.matchGroup(regex, input, group); if (result != null) { - // Continue if the result is null - break; + return result; } + + // Continue if the result is null } catch (final Parser.RegexException ignored) { } } - if (result == null) { - throw new Parser.RegexException("No regex matched the input on group " + group); - } - return result; + throw new Parser.RegexException("No regex matched the input on group " + group); } }