Skip to content

Commit 6d27996

Browse files
committed
Improve code of getStringResultFromRegexArray methods in Utils
1 parent 2e3da44 commit 6d27996

File tree

1 file changed

+10
-16
lines changed
  • extractor/src/main/java/org/schabi/newpipe/extractor/utils

1 file changed

+10
-16
lines changed

extractor/src/main/java/org/schabi/newpipe/extractor/utils/Utils.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -391,22 +391,19 @@ public static String getStringResultFromRegexArray(@Nonnull final String input,
391391
@Nonnull final String[] regexes,
392392
final int group)
393393
throws Parser.RegexException {
394-
String result = null;
395394
for (final String regex : regexes) {
396395
try {
397-
result = Parser.matchGroup(regex, input, group);
396+
final String result = Parser.matchGroup(regex, input, group);
398397
if (result != null) {
399-
// Continue if the result is null
400-
break;
398+
return result;
401399
}
400+
401+
// Continue if the result is null
402402
} catch (final Parser.RegexException ignored) {
403403
}
404404
}
405405

406-
if (result == null) {
407-
throw new Parser.RegexException("No regex matched the input on group " + group);
408-
}
409-
return result;
406+
throw new Parser.RegexException("No regex matched the input on group " + group);
410407
}
411408

412409
/**
@@ -425,21 +422,18 @@ public static String getStringResultFromRegexArray(@Nonnull final String input,
425422
@Nonnull final Pattern[] regexes,
426423
final int group)
427424
throws Parser.RegexException {
428-
String result = null;
429425
for (final Pattern regex : regexes) {
430426
try {
431-
result = Parser.matchGroup(regex, input, group);
427+
final String result = Parser.matchGroup(regex, input, group);
432428
if (result != null) {
433-
// Continue if the result is null
434-
break;
429+
return result;
435430
}
431+
432+
// Continue if the result is null
436433
} catch (final Parser.RegexException ignored) {
437434
}
438435
}
439436

440-
if (result == null) {
441-
throw new Parser.RegexException("No regex matched the input on group " + group);
442-
}
443-
return result;
437+
throw new Parser.RegexException("No regex matched the input on group " + group);
444438
}
445439
}

0 commit comments

Comments
 (0)