summaryrefslogtreecommitdiffstats
path: root/libhb/decsrtsub.c
diff options
context:
space:
mode:
authorRodeo <[email protected]>2013-05-08 21:51:00 +0000
committerRodeo <[email protected]>2013-05-08 21:51:00 +0000
commitd03eec7a91a06f76775bb863e892adbc87faea8d (patch)
tree59d53147038ba0dd368a524ccfe2f49c3a129646 /libhb/decsrtsub.c
parent2a9ec102706226a3b84f6e01ac0152a432d77332 (diff)
decsrtsub: rework character substitution logic.
Don't pointlessly convert a line break to a space if it's the last character. Also, only skip a CR character if it's followed by an LF character. Otherwise, replace it with an LF character or a space, depending on the line number. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5446 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/decsrtsub.c')
-rw-r--r--libhb/decsrtsub.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/libhb/decsrtsub.c b/libhb/decsrtsub.c
index 9bc9cedcd..4a827f460 100644
--- a/libhb/decsrtsub.c
+++ b/libhb/decsrtsub.c
@@ -321,7 +321,7 @@ static hb_buffer_t *srt_read( hb_work_private_t *pv )
*/
pv->last_entry_number = entry_number;
resync = 0;
- if( *pv->current_entry.text )
+ if (*pv->current_entry.text != '\0')
{
long length;
char *p, *q;
@@ -342,30 +342,35 @@ static hb_buffer_t *srt_read( hb_work_private_t *pv )
length = strlen( pv->current_entry.text );
- for( q = p = pv->current_entry.text; *p; p++)
+ for (q = p = pv->current_entry.text; *p != '\0'; p++)
{
- if( *p == '\n' )
+ if (*p == '\n' || *p == '\r')
{
- if ( line == 1 )
+ if (*(p + 1) == '\n' || *(p + 1) == '\0')
{
- *q = *p;
+ // followed by line break or last character, skip it
+ length--;
+ continue;
+ }
+ else if (line == 1)
+ {
+ // replace '\r' with '\n'
+ *q = '\n';
line = 2;
}
else
{
+ // all subtitles on one line
+ // replace line breaks with spaces
*q = ' ';
}
q++;
}
- else if( *p != '\r' )
+ else
{
*q = *p;
q++;
}
- else
- {
- length--;
- }
}
*q = '\0';
@@ -392,7 +397,7 @@ static hb_buffer_t *srt_read( hb_work_private_t *pv )
}
hb_buffer_t *buffer = NULL;
- if( *pv->current_entry.text )
+ if (*pv->current_entry.text != '\0')
{
long length;
char *p, *q;
@@ -411,30 +416,35 @@ static hb_buffer_t *srt_read( hb_work_private_t *pv )
length = strlen( pv->current_entry.text );
- for( q = p = pv->current_entry.text; *p; p++)
+ for (q = p = pv->current_entry.text; *p != '\0'; p++)
{
- if( *p == '\n' )
+ if (*p == '\n' || *p == '\r')
{
- if ( line == 1 )
+ if (*(p + 1) == '\n' || *(p + 1) == '\0')
{
- *q = *p;
+ // followed by line break or last character, skip it
+ length--;
+ continue;
+ }
+ else if (line == 1)
+ {
+ // replace '\r' with '\n'
+ *q = '\n';
line = 2;
}
else
{
+ // all subtitles on one line
+ // replace line breaks with spaces
*q = ' ';
}
q++;
}
- else if( *p != '\r' )
+ else
{
*q = *p;
q++;
}
- else
- {
- length--;
- }
}
*q = '\0';