Edit DASH UrlTemplate identifiers parser and add UrlTemplate tests
This commit is contained in:
parent
eb5cbd902b
commit
022444e751
@ -17,6 +17,8 @@ package androidx.media3.exoplayer.dash.manifest;
|
||||
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A template from which URLs can be built.
|
||||
@ -56,7 +58,10 @@ public final class UrlTemplate {
|
||||
int identifiersCount = 0;
|
||||
String[] identifiersNames = { REPRESENTATION, NUMBER, BANDWIDTH, TIME };
|
||||
for(String identifierName : identifiersNames){
|
||||
identifiersCount += template.split("\\$" + identifierName + "\\$").length - 1;
|
||||
Pattern pattern = Pattern.compile("(\\$" + identifierName + "\\$|" + ESCAPED_DOLLAR + "\\$" + identifierName + "\\$" + ESCAPED_DOLLAR +")");
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
while(matcher.find())
|
||||
identifiersCount++;
|
||||
}
|
||||
String[] urlPieces = new String[identifiersCount+1];
|
||||
int[] identifiers = new int[identifiersCount];
|
||||
|
@ -70,4 +70,20 @@ public class UrlTemplateTest {
|
||||
// Expected.
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullWithMultipleOccurrences(){
|
||||
String template = "$Bandwidth$_a1_$RepresentationID$_b1_$Time$_c1_$Number$_$Bandwidth$_a2_$RepresentationID$_b2_$Time$_c2_$Number$";
|
||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertThat(url).isEqualTo("650000_a1_abc1_b1_5000_c1_10_650000_a2_abc1_b2_5000_c2_10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fullWithMultipleOccurrencesAndDollarEscaping(){
|
||||
String template = "$$$Bandwidth$$$_a1$$_$RepresentationID$_b1_$Time$_c1_$Number$$$_$$$Bandwidth$$$_a2$$_$RepresentationID$_b2_$Time$_c2_$Number$$$";
|
||||
UrlTemplate urlTemplate = UrlTemplate.compile(template);
|
||||
String url = urlTemplate.buildUri("abc1", 10, 650000, 5000);
|
||||
assertThat(url).isEqualTo("$650000$_a1$_abc1_b1_5000_c1_10$_$650000$_a2$_abc1_b2_5000_c2_10$");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user