|
1 | 1 | package org.schabi.newpipe.extractor.utils; |
2 | 2 |
|
3 | | -import org.nibor.autolink.LinkExtractor; |
4 | | -import org.nibor.autolink.LinkSpan; |
5 | | -import org.nibor.autolink.LinkType; |
6 | | -import org.schabi.newpipe.extractor.exceptions.ParsingException; |
7 | | - |
8 | 3 | import java.io.UnsupportedEncodingException; |
9 | 4 | import java.net.URLDecoder; |
10 | 5 | import java.util.ArrayList; |
|
14 | 9 | import java.util.regex.Matcher; |
15 | 10 | import java.util.regex.Pattern; |
16 | 11 |
|
| 12 | +import org.nibor.autolink.LinkExtractor; |
| 13 | +import org.nibor.autolink.LinkSpan; |
| 14 | +import org.nibor.autolink.LinkType; |
| 15 | +import org.schabi.newpipe.extractor.exceptions.ParsingException; |
| 16 | + |
17 | 17 | /* |
18 | 18 | * Created by Christian Schabesberger on 02.02.16. |
19 | 19 | * |
@@ -51,18 +51,26 @@ public RegexException(String message) { |
51 | 51 | public static String matchGroup1(String pattern, String input) throws RegexException { |
52 | 52 | return matchGroup(pattern, input, 1); |
53 | 53 | } |
| 54 | + |
| 55 | + public static String matchGroup1(Pattern pattern, String input) throws RegexException { |
| 56 | + return matchGroup(pattern, input, 1); |
| 57 | + } |
54 | 58 |
|
55 | 59 | public static String matchGroup(String pattern, String input, int group) throws RegexException { |
56 | 60 | Pattern pat = Pattern.compile(pattern); |
| 61 | + return matchGroup(pat, input, group); |
| 62 | + } |
| 63 | + |
| 64 | + public static String matchGroup(Pattern pat, String input, int group) throws RegexException { |
57 | 65 | Matcher mat = pat.matcher(input); |
58 | 66 | boolean foundMatch = mat.find(); |
59 | 67 | if (foundMatch) { |
60 | 68 | return mat.group(group); |
61 | 69 | } else { |
62 | 70 | if (input.length() > 1024) { |
63 | | - throw new RegexException("failed to find pattern \"" + pattern); |
| 71 | + throw new RegexException("failed to find pattern \"" + pat.pattern()); |
64 | 72 | } else { |
65 | | - throw new RegexException("failed to find pattern \"" + pattern + " inside of " + input + "\""); |
| 73 | + throw new RegexException("failed to find pattern \"" + pat.pattern() + " inside of " + input + "\""); |
66 | 74 | } |
67 | 75 | } |
68 | 76 | } |
|
0 commit comments