mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-09-29 23:32:33 +00:00
gst/subparse/samiparse.c: Remove trailing, leading and double whitespaces.
Original commit message from CVS: * gst/subparse/samiparse.c: (handle_start_sync), (end_sami_element), (characters_sami): Remove trailing, leading and double whitespaces. Correctly timestamp buffers and output the last buffer too. * tests/check/elements/subparse.c: (GST_START_TEST), (subparse_suite): Add a simple unit test for SAMI parsing.
This commit is contained in:
parent
76e3ffb61c
commit
9333eb4899
3 changed files with 83 additions and 10 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2008-05-05 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
|
* gst/subparse/samiparse.c: (handle_start_sync),
|
||||||
|
(end_sami_element), (characters_sami):
|
||||||
|
Remove trailing, leading and double whitespaces.
|
||||||
|
Correctly timestamp buffers and output the last buffer too.
|
||||||
|
|
||||||
|
* tests/check/elements/subparse.c: (GST_START_TEST),
|
||||||
|
(subparse_suite):
|
||||||
|
Add a simple unit test for SAMI parsing.
|
||||||
|
|
||||||
2008-05-05 Sebastian Dröge <slomo@circular-chaos.org>
|
2008-05-05 Sebastian Dröge <slomo@circular-chaos.org>
|
||||||
|
|
||||||
Patch by: Young-Ho Cha <ganadist at chollian dot net>
|
Patch by: Young-Ho Cha <ganadist at chollian dot net>
|
||||||
|
|
|
@ -131,18 +131,13 @@ handle_start_sync (GstSamiContext * sctx, const xmlChar ** atts)
|
||||||
if (!value)
|
if (!value)
|
||||||
continue;
|
continue;
|
||||||
if (!xmlStrncmp ((const xmlChar *) "start", key, 5)) {
|
if (!xmlStrncmp ((const xmlChar *) "start", key, 5)) {
|
||||||
/* FIXME: this is not correct. According to[0] the start parameter
|
/* Only set a new start time if we don't have text pending */
|
||||||
* specifies the time when the text should be shown and not the time
|
if (sctx->resultbuf->len == 0)
|
||||||
* when the text should be hidden again.
|
sctx->time1 = sctx->time2;
|
||||||
* This essentially means that we have to look at the next sync element
|
|
||||||
* before pushing one buffer and push the last buffer with -1
|
|
||||||
* as duration after the body element is closed.
|
|
||||||
* [0] http://msdn.microsoft.com/en-us/library/ms971327.aspx
|
|
||||||
*/
|
|
||||||
sctx->time1 = sctx->time2;
|
|
||||||
sctx->time2 = atoi ((const char *) value) * GST_MSECOND;
|
sctx->time2 = atoi ((const char *) value) * GST_MSECOND;
|
||||||
sctx->has_result = TRUE;
|
|
||||||
g_string_append (sctx->resultbuf, sctx->buf->str);
|
g_string_append (sctx->resultbuf, sctx->buf->str);
|
||||||
|
sctx->has_result = (sctx->resultbuf->len != 0) ? TRUE : FALSE;
|
||||||
g_string_truncate (sctx->buf, 0);
|
g_string_truncate (sctx->buf, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,6 +243,19 @@ end_sami_element (void *ctx, const xmlChar * name)
|
||||||
|
|
||||||
if (!xmlStrncmp ((const xmlChar *) "sync", name, 4)) {
|
if (!xmlStrncmp ((const xmlChar *) "sync", name, 4)) {
|
||||||
sctx->in_sync = FALSE;
|
sctx->in_sync = FALSE;
|
||||||
|
} else if (!xmlStrncmp ((const xmlChar *) "body", name, 4)) {
|
||||||
|
/* We will usually have one buffer left when the body is closed
|
||||||
|
* as we need the next sync to actually send it */
|
||||||
|
if (sctx->buf->len != 0) {
|
||||||
|
/* Only set a new start time if we don't have text pending */
|
||||||
|
if (sctx->resultbuf->len == 0)
|
||||||
|
sctx->time1 = sctx->time2;
|
||||||
|
|
||||||
|
sctx->time2 = GST_CLOCK_TIME_NONE;
|
||||||
|
g_string_append (sctx->resultbuf, sctx->buf->str);
|
||||||
|
sctx->has_result = (sctx->resultbuf->len != 0) ? TRUE : FALSE;
|
||||||
|
g_string_truncate (sctx->buf, 0);
|
||||||
|
}
|
||||||
} else if (!xmlStrncmp ((const xmlChar *) "font", name, 4)) {
|
} else if (!xmlStrncmp ((const xmlChar *) "font", name, 4)) {
|
||||||
sami_context_pop_state (sctx, SPAN_TAG);
|
sami_context_pop_state (sctx, SPAN_TAG);
|
||||||
} else if (!xmlStrncmp ((const xmlChar *) "ruby", name, 4)) {
|
} else if (!xmlStrncmp ((const xmlChar *) "ruby", name, 4)) {
|
||||||
|
@ -262,12 +270,29 @@ characters_sami (void *ctx, const xmlChar * ch, int len)
|
||||||
{
|
{
|
||||||
GstSamiContext *sctx = (GstSamiContext *) ctx;
|
GstSamiContext *sctx = (GstSamiContext *) ctx;
|
||||||
gchar *escaped;
|
gchar *escaped;
|
||||||
|
gchar *tmp;
|
||||||
|
gint i;
|
||||||
|
|
||||||
/* Skip everything except content of the sync elements */
|
/* Skip everything except content of the sync elements */
|
||||||
if (!sctx->in_sync)
|
if (!sctx->in_sync)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
escaped = g_markup_escape_text ((const gchar *) ch, len);
|
escaped = g_markup_escape_text ((const gchar *) ch, len);
|
||||||
|
g_strstrip (escaped);
|
||||||
|
|
||||||
|
/* Remove double spaces forom the string as those are
|
||||||
|
* usually added by newlines and indention */
|
||||||
|
tmp = escaped;
|
||||||
|
for (i = 0; i <= strlen (escaped); i++) {
|
||||||
|
escaped[i] = *tmp;
|
||||||
|
if (*tmp != ' ') {
|
||||||
|
tmp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
while (*tmp == ' ')
|
||||||
|
tmp++;
|
||||||
|
}
|
||||||
|
|
||||||
if (has_tag (sctx->state, RT_TAG)) {
|
if (has_tag (sctx->state, RT_TAG)) {
|
||||||
g_string_append_c (sctx->rubybuf, ' ');
|
g_string_append_c (sctx->rubybuf, ' ');
|
||||||
g_string_append (sctx->rubybuf, escaped);
|
g_string_append (sctx->rubybuf, escaped);
|
||||||
|
|
|
@ -579,6 +579,42 @@ GST_START_TEST (test_subviewer2)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
GST_START_TEST (test_sami)
|
||||||
|
{
|
||||||
|
SubParseInputChunk sami_input[] = {
|
||||||
|
{"<SAMI>\n"
|
||||||
|
"<HEAD>\n"
|
||||||
|
" <TITLE>Subtitle</TITLE>\n"
|
||||||
|
" <STYLE TYPE=\"text/css\">\n"
|
||||||
|
" <!--\n"
|
||||||
|
" P {margin-left:8pt; margin-right:8pt; margin-bottom:2pt; margin-top:2pt; text-align:center; font-size:12pt; font-weight:normal; color:black;}\n"
|
||||||
|
" .CC {Name:English; lang:en-AU; SAMIType:CC;}\n"
|
||||||
|
" #STDPrn {Name:Standard Print;}\n"
|
||||||
|
" #LargePrn {Name:Large Print; font-size:24pt;}\n"
|
||||||
|
" #SmallPrn {Name:Small Print; font-size:16pt;}\n"
|
||||||
|
" -->\n"
|
||||||
|
" </Style>\n"
|
||||||
|
"</HEAD>\n"
|
||||||
|
"<BODY>\n"
|
||||||
|
" <SYNC Start=1000>\n"
|
||||||
|
" <P Class=CC>\n"
|
||||||
|
" This is a comment.<br>\n"
|
||||||
|
" This is a second comment.\n",
|
||||||
|
1000 * GST_MSECOND, 2000 * GST_MSECOND,
|
||||||
|
"This is a comment.\nThis is a second comment."},
|
||||||
|
{" <SYNC Start=2000>\n"
|
||||||
|
" <P Class=CC>\n"
|
||||||
|
" This is a third comment.<br>\n"
|
||||||
|
" This is a fourth comment.\n" "</BODY>\n" "</SAMI>\n",
|
||||||
|
2000 * GST_MSECOND, GST_CLOCK_TIME_NONE,
|
||||||
|
"This is a third comment.\nThis is a fourth comment."}
|
||||||
|
};
|
||||||
|
|
||||||
|
do_test (sami_input, G_N_ELEMENTS (sami_input), "text/x-pango-markup");
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
/* TODO:
|
/* TODO:
|
||||||
* - add/modify tests so that lines aren't dogfed to the parsers in complete
|
* - add/modify tests so that lines aren't dogfed to the parsers in complete
|
||||||
* lines or sets of complete lines, but rather in random chunks
|
* lines or sets of complete lines, but rather in random chunks
|
||||||
|
@ -606,6 +642,7 @@ subparse_suite (void)
|
||||||
tcase_add_test (tc_chain, test_mpl2);
|
tcase_add_test (tc_chain, test_mpl2);
|
||||||
tcase_add_test (tc_chain, test_subviewer);
|
tcase_add_test (tc_chain, test_subviewer);
|
||||||
tcase_add_test (tc_chain, test_subviewer2);
|
tcase_add_test (tc_chain, test_subviewer2);
|
||||||
|
tcase_add_test (tc_chain, test_sami);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue