Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public class SrtFromTtmlWriter {
private final boolean ignoreEmptyFrames;
private final Charset charset = StandardCharsets.UTF_8;

private int frameIndex = 0;
// According to the SubRip (.srt) specification, subtitle
// numbering must start from 1.
// Some players accept 0 or even negative indices,
// but to ensure compliance we start at 1.
private int frameIndex = 1;

public SrtFromTtmlWriter(final SharpStream out, final boolean ignoreEmptyFrames) {
this.out = out;
Expand All @@ -39,7 +43,8 @@ private static String getTimestamp(final Element frame, final String attr) {

private void writeFrame(final String begin, final String end, final StringBuilder text)
throws IOException {
writeString(String.valueOf(frameIndex++));
writeString(String.valueOf(frameIndex));
frameIndex += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use this because is just a write / increment and no read. Thus there is only little room for confusion.

Suggested change
frameIndex += 1;
frameIndex++;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion.
I agree that frameIndex++ works fine here and avoids confusion.

My earlier comment about i++ / ++i was only about using them directly inside something like writeString(String.valueOf(...)), which can indeed be confusing.

Between frameIndex += 1, frameIndex++, and frameIndex = frameIndex + 1, I personally prefer += 1 because it’s very explicit and leaves no room for overthinking.

I’m fine with switching to frameIndex++ if the team prefers, but my preference would be to keep += 1 if that’s acceptable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you’d like me to change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'm fine with either

writeString(NEW_LINE);
writeString(begin);
writeString(" --> ");
Expand Down