summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-05-09 17:50:19 +0200
committerDiego 'Flameeyes' Pettenò <flameeyes@gmail.com>2008-05-09 17:50:19 +0200
commita51427608e2f4543ae0cb0598517a1e4f6b0928b (patch)
tree7c4b0148c4d1b3d5224fb55dd772db1dd55baccb /src
parent4520cf440178ef98e859759e3fdbed4921703ac2 (diff)
downloadxine-lib-a51427608e2f4543ae0cb0598517a1e4f6b0928b.tar.gz
xine-lib-a51427608e2f4543ae0cb0598517a1e4f6b0928b.tar.bz2
Avoid transforming a string to uppecase, and avoid one call to strlen().
Instead of looping through the directive string as returned by sscanf() and transforming each character to its uppercase version, use strcasestr to run a case-insensitive sub-string search. Also avoid runing multiple strlen() calls per each line, use strncpy instead.
Diffstat (limited to 'src')
-rw-r--r--src/libsputext/demux_sputext.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c
index 47b7a3361..f7cd5af83 100644
--- a/src/libsputext/demux_sputext.c
+++ b/src/libsputext/demux_sputext.c
@@ -793,26 +793,19 @@ static subtitle_t *sub_read_line_jacobsub(demux_sputext_t *this, subtitle_t *cur
++p;
}
if (isalpha(*p)||*p == '[') {
- int cont, jLength;
-
if (sscanf(p, "%s %" LINE_LEN_QUOT "[^\n\r]", directive, line1) < 2)
return ERR;
- jLength = strlen(directive);
- for (cont = 0; cont < jLength; ++cont) {
- if (isalpha(*(directive + cont)))
- *(directive + cont) = toupper(*(directive + cont));
- }
- if ((strstr(directive, "RDB") != NULL)
- || (strstr(directive, "RDC") != NULL)
- || (strstr(directive, "RLB") != NULL)
- || (strstr(directive, "RLG") != NULL)) {
+ if ((strcasestr(directive, "RDB") != NULL)
+ || (strcasestr(directive, "RDC") != NULL)
+ || (strcasestr(directive, "RLB") != NULL)
+ || (strcasestr(directive, "RLG") != NULL)) {
continue;
}
/* no alignment */
#if 0
- if (strstr(directive, "JL") != NULL) {
+ if (strcasestr(directive, "JL") != NULL) {
current->alignment = SUB_ALIGNMENT_HLEFT;
- } else if (strstr(directive, "JR") != NULL) {
+ } else if (strcasestr(directive, "JR") != NULL) {
current->alignment = SUB_ALIGNMENT_HRIGHT;
} else {
current->alignment = SUB_ALIGNMENT_HCENTER;
@@ -1240,9 +1233,8 @@ static int demux_sputext_next (demux_sputext_t *this_gen) {
*val++ = (this->uses_time) ? sub->end * 10 : sub->end;
str = (char *)val;
for (line = 0; line < sub->lines; line++, str+=strlen(str)+1) {
- if( strlen(sub->text[line]) > SUB_BUFSIZE )
- sub->text[line][SUB_BUFSIZE] = '\0';
- strcpy(str, sub->text[line]);
+ strncpy(str, sub->text[line], SUB_BUFSIZE-1);
+ str[SUB_BUFSIZE-1] = '\0';
}
this->stream->video_fifo->put(this->stream->video_fifo, buf);