Skip to content

Commit

Permalink
google#4306 - breaking after the first alignment tag is found
Browse files Browse the repository at this point in the history
  • Loading branch information
szaboa committed Oct 1, 2018
1 parent 876080e commit fc5eb12
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public SubripDecoder() {
@Override
protected SubripSubtitle decode(byte[] bytes, int length, boolean reset) {
ArrayList<Cue> cues = new ArrayList<>();
ArrayList<String> tags = new ArrayList<>();
LongArray cueTimesUs = new LongArray();
ParsableByteArray subripData = new ParsableByteArray(bytes, length);
String currentLine;
Expand Down Expand Up @@ -120,6 +119,7 @@ protected SubripSubtitle decode(byte[] bytes, int length, boolean reset) {
}

// Read and parse the text.
ArrayList<String> tags = new ArrayList<>();
textBuilder.setLength(0);
while (!TextUtils.isEmpty(currentLine = subripData.readLine())) {
if (textBuilder.length() > 0) {
Expand All @@ -131,19 +131,15 @@ protected SubripSubtitle decode(byte[] bytes, int length, boolean reset) {
Spanned text = Html.fromHtml(textBuilder.toString());
Cue cue = null;

boolean alignTagFound = false;

// At end of this loop the clue must be created with the applied tags
for (String tag : tags) {

// Check if the tag is an alignment tag
if (tag.matches(SUBRIP_ALIGNMENT_TAG)) {

// Based on the specs, in case of the alignment tags only the first appearance counts
if (alignTagFound) continue;
alignTagFound = true;

cue = buildCue(text, tag);

// Based on the specs, in case of alignment tags only the first appearance counts, so break
break;
}
}

Expand Down

0 comments on commit fc5eb12

Please sign in to comment.