mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 862586 - Update webvtt parser to v0.4. r=cpearce
Update media/webvtt to the v0.4 tag of https://github.com/mozilla/webvtt.git master
This commit is contained in:
parent
7a281364ea
commit
c3e291a660
@ -1,5 +1,5 @@
|
||||
These files are from the WebVTT library, and are extracted from rev
|
||||
6b637c9f30911433e6d5a5be5d8512317a0d8a14 of the git repository at
|
||||
c93accafb2087df7c678748e25bca21f1173979f of the git repository at
|
||||
https://github.com/mozilla/webvtt.
|
||||
|
||||
The following CPPFLAGS are used in order to build and link in Mozilla
|
||||
|
@ -46,12 +46,14 @@ struct {
|
||||
static void *WEBVTT_CALLBACK
|
||||
default_alloc( void *unused, webvtt_uint nb )
|
||||
{
|
||||
(void)unused;
|
||||
return malloc( nb );
|
||||
}
|
||||
|
||||
static void WEBVTT_CALLBACK
|
||||
default_free( void *unused, void *ptr )
|
||||
{
|
||||
(void)unused;
|
||||
free( ptr );
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,7 @@ webvtt_create_cue( webvtt_cue **pcue )
|
||||
*/
|
||||
webvtt_ref( &cue->refs );
|
||||
webvtt_init_string( &cue->id );
|
||||
webvtt_init_string( &cue->body );
|
||||
cue->from = 0xFFFFFFFFFFFFFFFF;
|
||||
cue->until = 0xFFFFFFFFFFFFFFFF;
|
||||
cue->snap_to_lines = 1;
|
||||
@ -83,6 +84,7 @@ webvtt_release_cue( webvtt_cue **pcue )
|
||||
*pcue = 0;
|
||||
if( webvtt_deref( &cue->refs ) == 0 ) {
|
||||
webvtt_release_string( &cue->id );
|
||||
webvtt_release_string( &cue->body );
|
||||
webvtt_release_node( &cue->node_head );
|
||||
webvtt_free( cue );
|
||||
}
|
||||
@ -115,3 +117,9 @@ webvtt_validate_cue( webvtt_cue *cue )
|
||||
error:
|
||||
return 0;
|
||||
}
|
||||
|
||||
WEBVTT_INTERN webvtt_bool
|
||||
cue_is_incomplete( const webvtt_cue *cue ) {
|
||||
return !cue || ( cue->flags & CUE_HEADER_MASK ) == CUE_HAVE_ID;
|
||||
}
|
||||
|
||||
|
@ -47,9 +47,6 @@ enum {
|
||||
CUE_HEADER_MASK = CUE_HAVE_CUEPARAMS|CUE_HAVE_ID,
|
||||
};
|
||||
|
||||
static webvtt_bool
|
||||
cue_is_incomplete( const webvtt_cue *cue ) {
|
||||
return !cue || ( cue->flags & CUE_HEADER_MASK ) == CUE_HAVE_ID;
|
||||
}
|
||||
WEBVTT_INTERN webvtt_bool cue_is_incomplete( const webvtt_cue *cue );
|
||||
|
||||
#endif
|
||||
|
@ -29,11 +29,10 @@
|
||||
#include <string.h>
|
||||
#include "parser_internal.h"
|
||||
#include "cuetext_internal.h"
|
||||
#include "node_internal.h"
|
||||
#include "cue_internal.h"
|
||||
#include "string_internal.h"
|
||||
|
||||
static void webvtt_skipwhite( webvtt_byte **position );
|
||||
|
||||
#ifdef min
|
||||
# undef min
|
||||
#endif
|
||||
@ -67,19 +66,6 @@ do \
|
||||
goto dealloc; \
|
||||
} \
|
||||
|
||||
/**
|
||||
* This will only work on null-terminated strings, remember that!
|
||||
*/
|
||||
static void
|
||||
webvtt_skipwhite( webvtt_byte **position )
|
||||
{
|
||||
webvtt_byte *p = *position;
|
||||
while( *p && webvtt_iswhite(*p) ) {
|
||||
++p;
|
||||
}
|
||||
*position = p;
|
||||
}
|
||||
|
||||
WEBVTT_INTERN webvtt_status
|
||||
webvtt_create_token( webvtt_cuetext_token **token, webvtt_token_type token_type )
|
||||
{
|
||||
@ -175,19 +161,15 @@ webvtt_delete_token( webvtt_cuetext_token **token )
|
||||
* Note that time stamp tokens do not need to free any internal data because
|
||||
* they do not allocate anything.
|
||||
*/
|
||||
switch( t->token_type ) {
|
||||
case START_TOKEN:
|
||||
data = t->start_token_data;
|
||||
webvtt_release_stringlist( &data.css_classes );
|
||||
webvtt_release_string( &data.annotations );
|
||||
webvtt_release_string( &t->tag_name );
|
||||
break;
|
||||
case END_TOKEN:
|
||||
webvtt_release_string( &t->tag_name );
|
||||
break;
|
||||
case TEXT_TOKEN:
|
||||
webvtt_release_string( &t->text );
|
||||
break;
|
||||
if( t->token_type == START_TOKEN ) {
|
||||
data = t->start_token_data;
|
||||
webvtt_release_stringlist( &data.css_classes );
|
||||
webvtt_release_string( &data.annotations );
|
||||
webvtt_release_string( &t->tag_name );
|
||||
} else if( t->token_type == END_TOKEN ) {
|
||||
webvtt_release_string( &t->tag_name );
|
||||
} else if( t->token_type == TEXT_TOKEN ) {
|
||||
webvtt_release_string( &t->text );
|
||||
}
|
||||
webvtt_free( t );
|
||||
*token = 0;
|
||||
@ -196,7 +178,7 @@ webvtt_delete_token( webvtt_cuetext_token **token )
|
||||
WEBVTT_INTERN int
|
||||
tag_accepts_annotation( webvtt_string *tag_name )
|
||||
{
|
||||
return webvtt_string_is_equal( tag_name, "v", 1 );
|
||||
return webvtt_string_is_equal( tag_name, ( webvtt_byte * )"v", 1 );
|
||||
}
|
||||
|
||||
WEBVTT_INTERN webvtt_status
|
||||
@ -208,25 +190,25 @@ webvtt_node_kind_from_tag_name( webvtt_string *tag_name, webvtt_node_kind *kind
|
||||
|
||||
if( webvtt_string_length(tag_name) == 1 ) {
|
||||
switch( webvtt_string_text(tag_name)[0] ) {
|
||||
case( UTF8_B ):
|
||||
case( 'b' ):
|
||||
*kind = WEBVTT_BOLD;
|
||||
break;
|
||||
case( UTF8_I ):
|
||||
case( 'i' ):
|
||||
*kind = WEBVTT_ITALIC;
|
||||
break;
|
||||
case( UTF8_U ):
|
||||
case( 'u' ):
|
||||
*kind = WEBVTT_UNDERLINE;
|
||||
break;
|
||||
case( UTF8_C ):
|
||||
case( 'c' ):
|
||||
*kind = WEBVTT_CLASS;
|
||||
break;
|
||||
case( UTF8_V ):
|
||||
case( 'v' ):
|
||||
*kind = WEBVTT_VOICE;
|
||||
break;
|
||||
}
|
||||
} else if( webvtt_string_is_equal( tag_name, "ruby", 4 ) ) {
|
||||
} else if( webvtt_string_is_equal( tag_name, ( webvtt_byte * )"ruby", 4 ) ) {
|
||||
*kind = WEBVTT_RUBY;
|
||||
} else if( webvtt_string_is_equal( tag_name, "rt", 2 ) ) {
|
||||
} else if( webvtt_string_is_equal( tag_name, ( webvtt_byte * )"rt", 2 ) ) {
|
||||
*kind = WEBVTT_RUBY_TEXT;
|
||||
} else {
|
||||
return WEBVTT_INVALID_TAG_NAME;
|
||||
@ -279,17 +261,17 @@ webvtt_data_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
{
|
||||
for ( ; *token_state == DATA; (*position)++ ) {
|
||||
switch( **position ) {
|
||||
case UTF8_AMPERSAND:
|
||||
case '&':
|
||||
*token_state = ESCAPE;
|
||||
break;
|
||||
case UTF8_LESS_THAN:
|
||||
case '<':
|
||||
if( webvtt_string_length(result) == 0 ) {
|
||||
*token_state = TAG;
|
||||
} else {
|
||||
return WEBVTT_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case UTF8_NULL_BYTE:
|
||||
case '\0':
|
||||
return WEBVTT_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
@ -328,14 +310,14 @@ webvtt_escape_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
* Append ampersand here because the algorithm is not able to add it to the
|
||||
* buffer when it reads it in the DATA state tokenizer.
|
||||
*/
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( &buffer, UTF8_AMPERSAND ) );
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( &buffer, '&' ) );
|
||||
|
||||
for( ; *token_state == ESCAPE; (*position)++ ) {
|
||||
/**
|
||||
* We have encountered a token termination point.
|
||||
* Append buffer to result and return success.
|
||||
*/
|
||||
if( **position == UTF8_NULL_BYTE || **position == UTF8_LESS_THAN ) {
|
||||
if( **position == '\0' || **position == '<' ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append_string( result, &buffer ) );
|
||||
goto dealloc;
|
||||
}
|
||||
@ -344,7 +326,7 @@ webvtt_escape_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
* This means that we need to add that malformed text to the result and
|
||||
* recreate the buffer to prepare for a new escape sequence.
|
||||
*/
|
||||
else if( **position == UTF8_AMPERSAND ) {
|
||||
else if( **position == '&' ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append_string( result, &buffer ) );
|
||||
webvtt_release_string( &buffer );
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_create_string( 1, &buffer ) );
|
||||
@ -355,18 +337,18 @@ webvtt_escape_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
* Check if buffer contains a valid escape sequence and if it does append
|
||||
* the interpretation to result and change the state to DATA.
|
||||
*/
|
||||
else if( **position == UTF8_SEMI_COLON ) {
|
||||
if( webvtt_string_is_equal( &buffer, "&", 4 ) ) {
|
||||
else if( **position == ';' ) {
|
||||
if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&", 4 ) ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( result, '&' ) );
|
||||
} else if( webvtt_string_is_equal( &buffer, "<", 3 ) ) {
|
||||
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"<", 3 ) ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( result, '<' ) );
|
||||
} else if( webvtt_string_is_equal( &buffer, ">", 3 ) ) {
|
||||
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )">", 3 ) ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_putc( result, '>' ) );
|
||||
} else if( webvtt_string_is_equal( &buffer, "&rlm", 4 ) ) {
|
||||
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&rlm", 4 ) ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append( result, rlm_replace, RLM_REPLACE_LENGTH ) );
|
||||
} else if( webvtt_string_is_equal( &buffer, "&lrm", 4 ) ) {
|
||||
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )"&lrm", 4 ) ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append( result, lrm_replace, LRM_REPLACE_LENGTH ) );
|
||||
} else if( webvtt_string_is_equal( &buffer, " ", 5 ) ) {
|
||||
} else if( webvtt_string_is_equal( &buffer, ( webvtt_byte * )" ", 5 ) ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append( result, nbsp_replace, NBSP_REPLACE_LENGTH ) );
|
||||
} else {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_string_append_string( result, &buffer ) );
|
||||
@ -407,25 +389,25 @@ webvtt_tag_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
webvtt_string *result )
|
||||
{
|
||||
for( ; *token_state == TAG; (*position)++ ) {
|
||||
if( **position == UTF8_TAB || **position == UTF8_LINE_FEED ||
|
||||
**position == UTF8_CARRIAGE_RETURN || **position == UTF8_FORM_FEED ||
|
||||
**position == UTF8_SPACE ) {
|
||||
if( **position == '\t' || **position == '\n' ||
|
||||
**position == '\r' || **position == '\f' ||
|
||||
**position == ' ' ) {
|
||||
*token_state = START_TAG_ANNOTATION;
|
||||
} else if( webvtt_isdigit( **position ) ) {
|
||||
CHECK_MEMORY_OP( webvtt_string_putc( result, **position ) );
|
||||
*token_state = TIME_STAMP_TAG;
|
||||
} else {
|
||||
switch( **position ) {
|
||||
case UTF8_FULL_STOP:
|
||||
case '.':
|
||||
*token_state = START_TAG_CLASS;
|
||||
break;
|
||||
case UTF8_SOLIDUS:
|
||||
case '/':
|
||||
*token_state = END_TAG;
|
||||
break;
|
||||
case UTF8_GREATER_THAN:
|
||||
case '>':
|
||||
return WEBVTT_SUCCESS;
|
||||
break;
|
||||
case UTF8_NULL_BYTE:
|
||||
case '\0':
|
||||
return WEBVTT_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
@ -443,19 +425,19 @@ webvtt_start_tag_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
webvtt_string *result )
|
||||
{
|
||||
for( ; *token_state == START_TAG; (*position)++ ) {
|
||||
if( **position == UTF8_TAB || **position == UTF8_FORM_FEED ||
|
||||
**position == UTF8_SPACE || **position == UTF8_LINE_FEED ||
|
||||
**position == UTF8_CARRIAGE_RETURN ) {
|
||||
if( **position == '\t' || **position == '\f' ||
|
||||
**position == ' ' || **position == '\n' ||
|
||||
**position == '\r' ) {
|
||||
*token_state = START_TAG_ANNOTATION;
|
||||
} else {
|
||||
switch( **position ) {
|
||||
case UTF8_TAB:
|
||||
case '\t':
|
||||
*token_state = START_TAG_ANNOTATION;
|
||||
break;
|
||||
case UTF8_FULL_STOP:
|
||||
case '.':
|
||||
*token_state = START_TAG_CLASS;
|
||||
break;
|
||||
case UTF8_GREATER_THAN:
|
||||
case '>':
|
||||
return WEBVTT_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
@ -478,17 +460,17 @@ webvtt_class_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
CHECK_MEMORY_OP( webvtt_create_string( 1, &buffer ) );
|
||||
|
||||
for( ; *token_state == START_TAG_CLASS; (*position)++ ) {
|
||||
if( **position == UTF8_TAB || **position == UTF8_FORM_FEED ||
|
||||
**position == UTF8_SPACE || **position == UTF8_LINE_FEED ||
|
||||
**position == UTF8_CARRIAGE_RETURN) {
|
||||
if( **position == '\t' || **position == '\f' ||
|
||||
**position == ' ' || **position == '\n' ||
|
||||
**position == '\r') {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_stringlist_push( css_classes, &buffer ) );
|
||||
*token_state = START_TAG_ANNOTATION;
|
||||
return WEBVTT_SUCCESS;
|
||||
} else if( **position == UTF8_GREATER_THAN || **position == UTF8_NULL_BYTE ) {
|
||||
} else if( **position == '>' || **position == '\0' ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_stringlist_push( css_classes, &buffer ) );
|
||||
webvtt_release_string( &buffer );
|
||||
return WEBVTT_SUCCESS;
|
||||
} else if( **position == UTF8_FULL_STOP ) {
|
||||
} else if( **position == '.' ) {
|
||||
CHECK_MEMORY_OP_JUMP( status, webvtt_stringlist_push( css_classes, &buffer ) );
|
||||
webvtt_release_string( &buffer );
|
||||
CHECK_MEMORY_OP( webvtt_create_string( 1, &buffer ) );
|
||||
@ -508,7 +490,7 @@ webvtt_annotation_state( webvtt_byte **position, webvtt_token_state *token_state
|
||||
webvtt_string *annotation )
|
||||
{
|
||||
for( ; *token_state == START_TAG_ANNOTATION; (*position)++ ) {
|
||||
if( **position == UTF8_NULL_BYTE || **position == UTF8_GREATER_THAN ) {
|
||||
if( **position == '\0' || **position == '>' ) {
|
||||
return WEBVTT_SUCCESS;
|
||||
}
|
||||
CHECK_MEMORY_OP( webvtt_string_putc( annotation, **position ) );
|
||||
@ -522,7 +504,7 @@ webvtt_end_tag_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
webvtt_string *result )
|
||||
{
|
||||
for( ; *token_state == END_TAG; (*position)++ ) {
|
||||
if( **position == UTF8_GREATER_THAN || **position == UTF8_NULL_BYTE ) {
|
||||
if( **position == '>' || **position == '\0' ) {
|
||||
return WEBVTT_SUCCESS;
|
||||
}
|
||||
CHECK_MEMORY_OP( webvtt_string_putc( result, **position ) );
|
||||
@ -536,7 +518,7 @@ webvtt_timestamp_state( webvtt_byte **position, webvtt_token_state *token_state,
|
||||
webvtt_string *result )
|
||||
{
|
||||
for( ; *token_state == TIME_STAMP_TAG; (*position)++ ) {
|
||||
if( **position == UTF8_GREATER_THAN || **position == UTF8_NULL_BYTE ) {
|
||||
if( **position == '>' || **position == '\0' ) {
|
||||
return WEBVTT_SUCCESS;
|
||||
}
|
||||
CHECK_MEMORY_OP( webvtt_string_putc( result, **position ) );
|
||||
@ -599,13 +581,9 @@ webvtt_cuetext_tokenizer( webvtt_byte **position, webvtt_cuetext_token **token )
|
||||
status = webvtt_timestamp_state( position, &token_state, &result );
|
||||
break;
|
||||
}
|
||||
|
||||
if( token_state == START_TAG_ANNOTATION ) {
|
||||
webvtt_skipwhite( position );
|
||||
}
|
||||
}
|
||||
|
||||
if( **position == UTF8_GREATER_THAN )
|
||||
if( **position == '>' )
|
||||
{ (*position)++; }
|
||||
|
||||
if( status == WEBVTT_SUCCESS ) {
|
||||
@ -661,6 +639,16 @@ webvtt_parse_cuetext( webvtt_parser self, webvtt_cue *cue, webvtt_string *payloa
|
||||
webvtt_cuetext_token *token;
|
||||
webvtt_node_kind kind;
|
||||
|
||||
/**
|
||||
* TODO: Use these parameters! 'finished' isn't really important
|
||||
* here, but 'self' certainly is as it lets us report syntax errors.
|
||||
*
|
||||
* However, for the time being we can trick the compiler into not
|
||||
* warning us about unused variables by doing this.
|
||||
*/
|
||||
( void )self;
|
||||
( void )finished;
|
||||
|
||||
if( !cue ) {
|
||||
return WEBVTT_INVALID_PARAM;
|
||||
}
|
||||
@ -685,74 +673,68 @@ webvtt_parse_cuetext( webvtt_parser self, webvtt_cue *cue, webvtt_string *payloa
|
||||
* Routine taken from the W3C specification
|
||||
* http://dev.w3.org/html5/webvtt/#webvtt-cue-text-parsing-rules
|
||||
*/
|
||||
while( *position != UTF8_NULL_BYTE ) {
|
||||
|
||||
while( *position != '\0' ) {
|
||||
webvtt_status status = WEBVTT_SUCCESS;
|
||||
webvtt_delete_token( &token );
|
||||
|
||||
/* Step 7. */
|
||||
switch( webvtt_cuetext_tokenizer( &position, &token ) ) {
|
||||
case( WEBVTT_UNFINISHED ):
|
||||
/* Error here. */
|
||||
break;
|
||||
/* Step 8. */
|
||||
case( WEBVTT_SUCCESS ):
|
||||
|
||||
if( WEBVTT_FAILED( status = webvtt_cuetext_tokenizer( &position,
|
||||
&token ) ) ) {
|
||||
/* Error here. */
|
||||
} else {
|
||||
/* Succeeded... Process token */
|
||||
if( token->token_type == END_TOKEN ) {
|
||||
/**
|
||||
* If we've found an end token which has a valid end token tag name and
|
||||
* a tag name that is equal to the current node then set current to the
|
||||
* parent of current.
|
||||
*/
|
||||
if( token->token_type == END_TOKEN ) {
|
||||
if( current_node->kind == WEBVTT_HEAD_NODE ) {
|
||||
/**
|
||||
* We have encountered an end token but we are at the top of the list
|
||||
* and thus have not encountered any start tokens yet, throw away the
|
||||
* token.
|
||||
*/
|
||||
if( current_node->kind == WEBVTT_HEAD_NODE ) {
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if( webvtt_node_kind_from_tag_name( &token->tag_name, &kind ) == WEBVTT_INVALID_TAG_NAME ) {
|
||||
/**
|
||||
* We have encountered an end token but it is not in a format that is
|
||||
* supported, throw away the token.
|
||||
*/
|
||||
if( webvtt_node_kind_from_tag_name( &token->tag_name, &kind ) == WEBVTT_INVALID_TAG_NAME ) {
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if( current_node->kind == kind ) {
|
||||
/**
|
||||
* We have encountered an end token and it matches the start token of
|
||||
* the node that we are currently on. Move back up the list of nodes
|
||||
* and continue parsing.
|
||||
*/
|
||||
if( current_node->kind == kind ) {
|
||||
current_node = current_node->parent;
|
||||
}
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Attempt to create a valid node from the token.
|
||||
* If successful then attach the node to the current nodes list and
|
||||
* also set current to the newly created node if it is an internal
|
||||
* node type.
|
||||
*/
|
||||
if( webvtt_create_node_from_token( token, &temp_node, current_node ) != WEBVTT_SUCCESS ) {
|
||||
/* Do something here? */
|
||||
}
|
||||
else {
|
||||
webvtt_attach_node( current_node, temp_node );
|
||||
|
||||
if( WEBVTT_IS_VALID_INTERNAL_NODE( temp_node->kind ) ) {
|
||||
current_node = temp_node;
|
||||
}
|
||||
|
||||
/* Release the node as attach internal node increases the count. */
|
||||
webvtt_release_node( &temp_node );
|
||||
}
|
||||
current_node = current_node->parent;
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
/**
|
||||
* Attempt to create a valid node from the token.
|
||||
* If successful then attach the node to the current nodes list and
|
||||
* also set current to the newly created node if it is an internal
|
||||
* node type.
|
||||
*/
|
||||
if( webvtt_create_node_from_token( token, &temp_node, current_node ) != WEBVTT_SUCCESS ) {
|
||||
/* Do something here? */
|
||||
} else {
|
||||
webvtt_attach_node( current_node, temp_node );
|
||||
|
||||
if( WEBVTT_IS_VALID_INTERNAL_NODE( temp_node->kind ) ) {
|
||||
current_node = temp_node;
|
||||
}
|
||||
|
||||
/* Release the node as attach internal node increases the count. */
|
||||
webvtt_release_node( &temp_node );
|
||||
}
|
||||
}
|
||||
}
|
||||
webvtt_skipwhite( &position );
|
||||
}
|
||||
|
||||
webvtt_delete_token( &token );
|
||||
|
@ -81,6 +81,7 @@ webvtt_cue_t {
|
||||
webvtt_cue_settings settings;
|
||||
webvtt_bool snap_to_lines;
|
||||
webvtt_string id;
|
||||
webvtt_string body;
|
||||
|
||||
/**
|
||||
* Parsed cue-text (NULL if has not been parsed)
|
||||
|
@ -71,11 +71,20 @@ webvtt_node_kind_t {
|
||||
WEBVTT_EMPTY_NODE = 258
|
||||
} webvtt_node_kind;
|
||||
|
||||
#define WEBVTT_IS_LEAF(Kind) ( ((Kind) & WEBVTT_NODE_LEAF) != 0 )
|
||||
#define WEBVTT_NODE_INDEX(Kind) ( (Kind) & ~WEBVTT_NODE_LEAF )
|
||||
#define WEBVTT_IS_VALID_LEAF_NODE(Kind) ( WEBVTT_IS_LEAF(Kind) && (WEBVTT_NODE_INDEX(Kind) >= WEBVTT_NODE_LEAF_START && WEBVTT_NODE_INDEX(Kind) <= WEBVTT_NODE_LEAF_END ) )
|
||||
#define WEBVTT_IS_VALID_INTERNAL_NODE(Kind) ( (!WEBVTT_IS_LEAF(Kind)) && (WEBVTT_NODE_INDEX(Kind) >= WEBVTT_NODE_INTERNAL_START && WEBVTT_NODE_INDEX(Kind) <= WEBVTT_NODE_INTERNAL_END) )
|
||||
#define WEBVTT_IS_VALID_NODE_KIND(Kind) ( WEBVTT_IS_VALID_INTERNAL_NODE(Kind) || WEBVTT_IS_VALID_LEAF_NODE(Kind) )
|
||||
#define WEBVTT_IS_LEAF( Kind ) ( ( ( Kind ) & WEBVTT_NODE_LEAF) != 0 )
|
||||
#define WEBVTT_NODE_INDEX( Kind ) ( ( Kind ) & ~WEBVTT_NODE_LEAF )
|
||||
|
||||
#define WEBVTT_IS_VALID_LEAF_NODE( Kind ) \
|
||||
( WEBVTT_IS_LEAF( Kind ) && \
|
||||
( WEBVTT_NODE_INDEX( Kind ) >= WEBVTT_NODE_LEAF_START && \
|
||||
WEBVTT_NODE_INDEX( Kind ) <= WEBVTT_NODE_LEAF_END ) )
|
||||
|
||||
#define WEBVTT_IS_VALID_INTERNAL_NODE( Kind ) \
|
||||
( ( !WEBVTT_IS_LEAF( Kind ) ) && \
|
||||
( WEBVTT_NODE_INDEX( Kind ) <= WEBVTT_NODE_INTERNAL_END ) )
|
||||
|
||||
#define WEBVTT_IS_VALID_NODE_KIND( Kind ) \
|
||||
( WEBVTT_IS_VALID_INTERNAL_NODE( Kind ) || WEBVTT_IS_VALID_LEAF_NODE( Kind ) )
|
||||
|
||||
struct webvtt_internal_node_data_t;
|
||||
|
||||
|
@ -126,14 +126,14 @@ WEBVTT_EXPORT const webvtt_byte *webvtt_string_text( const webvtt_string *str );
|
||||
*
|
||||
* return the length of a strings text
|
||||
*/
|
||||
WEBVTT_EXPORT const webvtt_uint32 webvtt_string_length( const webvtt_string *str );
|
||||
WEBVTT_EXPORT webvtt_uint32 webvtt_string_length( const webvtt_string *str );
|
||||
|
||||
/**
|
||||
* webvtt_string_capacity
|
||||
*
|
||||
* return the current capacity of a string
|
||||
*/
|
||||
WEBVTT_EXPORT const webvtt_uint32 webvtt_string_capacity( const webvtt_string *str );
|
||||
WEBVTT_EXPORT webvtt_uint32 webvtt_string_capacity( const webvtt_string *str );
|
||||
|
||||
/**
|
||||
* webvtt_string_getline
|
||||
@ -142,7 +142,7 @@ WEBVTT_EXPORT const webvtt_uint32 webvtt_string_capacity( const webvtt_string *s
|
||||
* including the terminating character(s)
|
||||
*/
|
||||
WEBVTT_EXPORT int webvtt_string_getline( webvtt_string *str, const webvtt_byte *buffer,
|
||||
webvtt_uint *pos, webvtt_uint len, int *truncate, webvtt_bool finish, webvtt_bool retain_new_line );
|
||||
webvtt_uint *pos, int len, int *truncate, webvtt_bool finish );
|
||||
|
||||
/**
|
||||
* webvtt_string_putc
|
||||
@ -158,7 +158,8 @@ WEBVTT_EXPORT webvtt_status webvtt_string_putc( webvtt_string *str, webvtt_byte
|
||||
* compare a string's text to a byte array
|
||||
*
|
||||
*/
|
||||
WEBVTT_EXPORT webvtt_bool webvtt_string_is_equal( webvtt_string *str, webvtt_byte *to_compare, webvtt_uint len );
|
||||
WEBVTT_EXPORT webvtt_bool webvtt_string_is_equal( const webvtt_string *str,
|
||||
const webvtt_byte *to_compare, int len );
|
||||
|
||||
/**
|
||||
* webvtt_string_append
|
||||
|
@ -125,7 +125,7 @@
|
||||
#define OR
|
||||
#define AND
|
||||
|
||||
#define OVERFLOW(X) \
|
||||
#define IF_OVERFLOW(X) \
|
||||
if( self->token_pos >= (sizeof(self->token) - 1 ) ) \
|
||||
{ \
|
||||
RETURN(X) \
|
||||
@ -156,7 +156,6 @@ webvtt_lex_word( webvtt_parser self, webvtt_string *str, const webvtt_byte *buff
|
||||
{
|
||||
webvtt_status status = WEBVTT_SUCCESS;
|
||||
webvtt_uint pos = *ppos;
|
||||
int d = 0;
|
||||
if( !str ) {
|
||||
return WEBVTT_INVALID_PARAM;
|
||||
}
|
||||
@ -193,6 +192,83 @@ _finished:
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* webvtt_lex_newline
|
||||
*
|
||||
* Get newline sequence in re-entrant fashion. self->tstate must be
|
||||
* L_START or L_NEWLINE0 for this function to behave correctly.
|
||||
*/
|
||||
WEBVTT_INTERN webvtt_token
|
||||
webvtt_lex_newline( webvtt_parser self, const
|
||||
webvtt_byte *buffer, webvtt_uint *pos, webvtt_uint length,
|
||||
webvtt_bool finish )
|
||||
{
|
||||
webvtt_uint p = *pos;
|
||||
|
||||
/* Ensure that we've got a valid token-state for this use-case. */
|
||||
DIE_IF( self->tstate != L_START && self->tstate != L_NEWLINE0 );
|
||||
|
||||
while( p < length ) {
|
||||
webvtt_byte c = buffer[ p++ ];
|
||||
self->token[ self->token_pos++ ] = c;
|
||||
self->token[ self->token_pos ] = 0;
|
||||
self->bytes++;
|
||||
|
||||
switch( self->tstate ) {
|
||||
case L_START:
|
||||
if( c == '\n' ) {
|
||||
*pos = p;
|
||||
return NEWLINE;
|
||||
} else if( c == '\r' ) {
|
||||
self->tstate = L_NEWLINE0;
|
||||
} else {
|
||||
goto backup;
|
||||
}
|
||||
break;
|
||||
case L_NEWLINE0:
|
||||
if( c == '\n' ) {
|
||||
*pos = p;
|
||||
self->tstate = L_START;
|
||||
return NEWLINE;
|
||||
} else {
|
||||
goto backup;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
/**
|
||||
* This should never happen if the function is called correctly
|
||||
* (EG immediately following a successful call to webvtt_string_getline)
|
||||
*/
|
||||
goto backup;
|
||||
}
|
||||
}
|
||||
|
||||
*pos = p;
|
||||
if( finish && ( p >= length ) ) {
|
||||
/* If pos >= length, it's and 'finish' is set, it's an automatic EOL */
|
||||
self->tstate = L_START;
|
||||
return NEWLINE;
|
||||
}
|
||||
|
||||
if( self->tstate == L_NEWLINE0 ) {
|
||||
return UNFINISHED;
|
||||
} else {
|
||||
/* This branch should never occur, if the function is used properly. */
|
||||
*pos = --p;
|
||||
return BADTOKEN;
|
||||
}
|
||||
backup:
|
||||
self->token[ --self->token_pos ] = 0;
|
||||
--self->bytes;
|
||||
*pos = --p;
|
||||
if( self->tstate == L_NEWLINE0 ) {
|
||||
self->tstate = L_START;
|
||||
return NEWLINE;
|
||||
}
|
||||
return BADTOKEN;
|
||||
}
|
||||
|
||||
WEBVTT_INTERN webvtt_token
|
||||
webvtt_lex( webvtt_parser self, const webvtt_byte *buffer, webvtt_uint *pos, webvtt_uint length, webvtt_bool finish )
|
||||
{
|
||||
@ -269,10 +345,17 @@ webvtt_lex( webvtt_parser self, const webvtt_byte *buffer, webvtt_uint *pos, web
|
||||
|
||||
BEGIN_STATE(L_DIGIT0)
|
||||
U_DIGIT {
|
||||
OVERFLOW(INTEGER)
|
||||
IF_OVERFLOW(INTEGER)
|
||||
SET_STATE(L_DIGIT0)
|
||||
}
|
||||
U_COLON { SET_STATE(L_TIMESTAMP1) }
|
||||
U_COLON {
|
||||
/* Don't return a TIMESTAMP if we start with '-' */
|
||||
if( self->token[0] == '-' ) {
|
||||
RETURN(INTEGER);
|
||||
} else {
|
||||
SET_STATE(L_TIMESTAMP1)
|
||||
}
|
||||
}
|
||||
U_PERCENT { RETURN(PERCENTAGE) }
|
||||
DEFAULT { BACKUP AND RETURN(INTEGER) }
|
||||
END_STATE_EX
|
||||
@ -283,7 +366,7 @@ webvtt_lex( webvtt_parser self, const webvtt_byte *buffer, webvtt_uint *pos, web
|
||||
END_STATE_EX
|
||||
|
||||
BEGIN_STATE(L_WHITESPACE)
|
||||
U_SPACE OR U_TAB { OVERFLOW(WHITESPACE) SET_STATE(L_WHITESPACE) }
|
||||
U_SPACE OR U_TAB { IF_OVERFLOW(WHITESPACE) SET_STATE(L_WHITESPACE) }
|
||||
DEFAULT { BACKUP RETURN(WHITESPACE) }
|
||||
END_STATE_EX
|
||||
|
||||
@ -453,37 +536,42 @@ webvtt_lex( webvtt_parser self, const webvtt_byte *buffer, webvtt_uint *pos, web
|
||||
|
||||
BEGIN_STATE(L_TIMESTAMP1)
|
||||
U_DIGIT {
|
||||
OVERFLOW(BADTOKEN)
|
||||
IF_OVERFLOW(BADTOKEN)
|
||||
SET_STATE(L_TIMESTAMP1)
|
||||
}
|
||||
U_COLON {
|
||||
OVERFLOW(BADTOKEN)
|
||||
IF_OVERFLOW(BADTOKEN)
|
||||
SET_STATE(L_TIMESTAMP2)
|
||||
}
|
||||
U_PERIOD {
|
||||
OVERFLOW(BADTOKEN)
|
||||
IF_OVERFLOW(BADTOKEN)
|
||||
SET_STATE(L_TIMESTAMP3)
|
||||
}
|
||||
END_STATE
|
||||
|
||||
BEGIN_STATE(L_TIMESTAMP2)
|
||||
U_DIGIT {
|
||||
OVERFLOW(BADTOKEN)
|
||||
IF_OVERFLOW(BADTOKEN)
|
||||
SET_STATE(L_TIMESTAMP2)
|
||||
}
|
||||
U_PERIOD {
|
||||
OVERFLOW(BADTOKEN)
|
||||
IF_OVERFLOW(BADTOKEN)
|
||||
SET_STATE(L_TIMESTAMP3)
|
||||
}
|
||||
END_STATE
|
||||
|
||||
BEGIN_STATE(L_TIMESTAMP3)
|
||||
U_DIGIT {
|
||||
OVERFLOW(TIMESTAMP)
|
||||
IF_OVERFLOW(TIMESTAMP)
|
||||
BREAK
|
||||
}
|
||||
DEFAULT {
|
||||
BACKUP
|
||||
/* Don't return a TIMESTAMP if we don't have at least one
|
||||
millisecond */
|
||||
if( !webvtt_isdigit( self->token[ self->token_pos - 1 ] ) ) {
|
||||
RETURN(BADTOKEN);
|
||||
}
|
||||
RETURN(TIMESTAMP)
|
||||
BREAK
|
||||
}
|
||||
|
@ -32,7 +32,8 @@
|
||||
static webvtt_node empty_node = {
|
||||
{ 1 }, /* init ref count */
|
||||
0, /* parent */
|
||||
WEBVTT_EMPTY_NODE /* node kind */
|
||||
WEBVTT_EMPTY_NODE, /* node kind */
|
||||
{ { 0 } } /* value */
|
||||
};
|
||||
|
||||
WEBVTT_EXPORT void
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -144,18 +144,21 @@ webvtt_parse_state_t {
|
||||
*/
|
||||
typedef enum
|
||||
webvtt_lexer_state_t {
|
||||
L_START = 0, L_BOM0, L_BOM1, L_WEBVTT0, L_WEBVTT1, L_WEBVTT2, L_WEBVTT3, L_WEBVTT4, L_WEBVTT5, L_DASH0, L_SEP1,
|
||||
L_DIGIT0, L_NEWLINE0, L_WHITESPACE, L_POSITION0, L_POSITION1, L_POSITION2, L_POSITION3, L_POSITION4, L_POSITION5,
|
||||
L_POSITION6, L_ALIGN0, L_ALIGN1, L_ALIGN2, L_ALIGN3, L_L0, L_LINE1, L_LINE2, L_LINE3,
|
||||
L_VERTICAL0, L_VERTICAL1, L_VERTICAL2, L_VERTICAL3, L_VERTICAL4, L_VERTICAL5, L_VERTICAL6, L_RL0,
|
||||
L_S0, L_SIZE1, L_SIZE2, L_START1, L_START2, L_START3, L_MIDDLE0, L_MIDDLE1, L_MIDDLE2, L_MIDDLE3,
|
||||
L_MIDDLE4, L_END0, L_END1, L_TIMESTAMP1, L_TIMESTAMP2, L_TIMESTAMP3, L_RIGHT1, L_RIGHT2,
|
||||
L_RIGHT3, L_NOTE1, L_NOTE2, L_NOTE3, L_LEFT1, L_LEFT2,
|
||||
L_START = 0, L_BOM0, L_BOM1, L_WEBVTT0, L_WEBVTT1, L_WEBVTT2, L_WEBVTT3,
|
||||
L_WEBVTT4, L_DASH0, L_SEP1, L_DIGIT0, L_NEWLINE0, L_WHITESPACE, L_POSITION0,
|
||||
L_POSITION1, L_POSITION2, L_POSITION3, L_POSITION4, L_POSITION5, L_POSITION6,
|
||||
L_ALIGN0, L_ALIGN1, L_ALIGN2, L_ALIGN3, L_L0, L_LINE1, L_LINE2, L_VERTICAL0,
|
||||
L_VERTICAL1, L_VERTICAL2, L_VERTICAL3, L_VERTICAL4, L_VERTICAL5, L_VERTICAL6,
|
||||
L_RL0, L_S0, L_SIZE1, L_SIZE2, L_START1, L_START2, L_START3, L_MIDDLE0,
|
||||
L_MIDDLE1, L_MIDDLE2, L_MIDDLE3, L_MIDDLE4, L_END0, L_END1, L_TIMESTAMP1,
|
||||
L_TIMESTAMP2, L_TIMESTAMP3, L_RIGHT1, L_RIGHT2, L_RIGHT3, L_NOTE1, L_NOTE2,
|
||||
L_NOTE3, L_LEFT1, L_LEFT2,
|
||||
} webvtt_lexer_state;
|
||||
|
||||
typedef struct
|
||||
webvtt_state {
|
||||
webvtt_parse_state state;
|
||||
webvtt_uint flags; /* Defaults to 0 when pushed */
|
||||
webvtt_token token;
|
||||
webvtt_state_value_type type;
|
||||
webvtt_uint back;
|
||||
@ -199,6 +202,8 @@ webvtt_parser_t {
|
||||
void *userdata;
|
||||
webvtt_bool finished;
|
||||
|
||||
webvtt_uint cuetext_line; /* start line of cuetext */
|
||||
|
||||
/**
|
||||
* 'mode' can have several states, it is not boolean.
|
||||
*/
|
||||
@ -227,8 +232,47 @@ webvtt_parser_t {
|
||||
|
||||
WEBVTT_INTERN webvtt_token webvtt_lex( webvtt_parser self, const webvtt_byte *buffer, webvtt_uint *pos, webvtt_uint length, webvtt_bool finish );
|
||||
WEBVTT_INTERN webvtt_status webvtt_lex_word( webvtt_parser self, webvtt_string *pba, const webvtt_byte *buffer, webvtt_uint *pos, webvtt_uint length, webvtt_bool finish );
|
||||
|
||||
/* Tokenize newline sequence, without incrementing 'self->line'. Returns
|
||||
* BAD_TOKEN when a newline sequence is not found. */
|
||||
WEBVTT_INTERN webvtt_token webvtt_lex_newline( webvtt_parser self, const
|
||||
webvtt_byte *buffer, webvtt_uint *pos, webvtt_uint length, webvtt_bool finish );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_proc_cueline( webvtt_parser self,
|
||||
webvtt_cue *cue, webvtt_string *line );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_parse_align( webvtt_parser self,
|
||||
webvtt_cue *cue, const webvtt_byte *text, webvtt_uint *pos, webvtt_uint len );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_parse_line( webvtt_parser self,
|
||||
webvtt_cue *cue, const webvtt_byte *text, webvtt_uint *pos, webvtt_uint len );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_parse_position( webvtt_parser self,
|
||||
webvtt_cue *cue, const webvtt_byte *text, webvtt_uint *pos, webvtt_uint len );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_parse_size( webvtt_parser self,
|
||||
webvtt_cue *cue, const webvtt_byte *text, webvtt_uint *pos, webvtt_uint len );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_parse_vertical( webvtt_parser self,
|
||||
webvtt_cue *cue, const webvtt_byte *text, webvtt_uint *pos, webvtt_uint len );
|
||||
|
||||
WEBVTT_INTERN int parse_timestamp( const webvtt_byte *b, webvtt_timestamp *result );
|
||||
|
||||
WEBVTT_INTERN webvtt_status do_push( webvtt_parser self, webvtt_uint token,
|
||||
webvtt_uint back, webvtt_uint state, void *data, webvtt_state_value_type type,
|
||||
webvtt_uint line, webvtt_uint column );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_read_cuetext( webvtt_parser self,
|
||||
const webvtt_byte *b, webvtt_uint *ppos, webvtt_uint len,
|
||||
webvtt_bool finish );
|
||||
|
||||
WEBVTT_INTERN webvtt_status webvtt_proc_cuetext( webvtt_parser self,
|
||||
const webvtt_byte *b, webvtt_uint *ppos, webvtt_uint len,
|
||||
webvtt_bool finish );
|
||||
|
||||
WEBVTT_INTERN int parse_cueparams( webvtt_parser self, const webvtt_byte *text,
|
||||
webvtt_uint len, webvtt_cue *cue );
|
||||
|
||||
/**
|
||||
* Flags which can apply additional meaning to a token. find_token() will
|
||||
* test for only the actual token and ignore the additional flags.
|
||||
|
@ -84,8 +84,6 @@ webvtt_create_string( webvtt_uint32 alloc, webvtt_string *result )
|
||||
WEBVTT_EXPORT webvtt_status
|
||||
webvtt_create_string_with_text( webvtt_string *result, const webvtt_byte *init_text, int len )
|
||||
{
|
||||
webvtt_uint pos = 0;
|
||||
|
||||
if( !result ) {
|
||||
return WEBVTT_INVALID_PARAM;
|
||||
}
|
||||
@ -200,7 +198,7 @@ webvtt_string_text(const webvtt_string *str)
|
||||
return str->d->text;
|
||||
}
|
||||
|
||||
WEBVTT_EXPORT const webvtt_uint32
|
||||
WEBVTT_EXPORT webvtt_uint32
|
||||
webvtt_string_length(const webvtt_string *str)
|
||||
{
|
||||
if( !str || !str->d )
|
||||
@ -211,7 +209,7 @@ webvtt_string_length(const webvtt_string *str)
|
||||
return str->d->length;
|
||||
}
|
||||
|
||||
WEBVTT_EXPORT const webvtt_uint32
|
||||
WEBVTT_EXPORT webvtt_uint32
|
||||
webvtt_string_capacity(const webvtt_string *str)
|
||||
{
|
||||
if( !str || !str->d )
|
||||
@ -287,14 +285,15 @@ grow( webvtt_string *str, webvtt_uint need )
|
||||
|
||||
WEBVTT_EXPORT int
|
||||
webvtt_string_getline( webvtt_string *src, const webvtt_byte *buffer,
|
||||
webvtt_uint *pos, webvtt_uint len, int *truncate, webvtt_bool finish, webvtt_bool retain_new_line )
|
||||
webvtt_uint *pos, int len, int *truncate,
|
||||
webvtt_bool finish )
|
||||
{
|
||||
int ret = 0;
|
||||
webvtt_string *str = src;
|
||||
webvtt_string_data *d = 0;
|
||||
const webvtt_byte *s = buffer + *pos;
|
||||
const webvtt_byte *p = s;
|
||||
const webvtt_byte *n = buffer + len;
|
||||
const webvtt_byte *n;
|
||||
|
||||
/**
|
||||
*if this is public now, maybe we should return webvtt_status so we can
|
||||
@ -312,13 +311,13 @@ webvtt_string_getline( webvtt_string *src, const webvtt_byte *buffer,
|
||||
}
|
||||
d = str->d;
|
||||
}
|
||||
|
||||
while( p < n && *p != UTF8_CARRIAGE_RETURN && *p != UTF8_LINE_FEED ) {
|
||||
++p;
|
||||
if( len < 0 ) {
|
||||
len = strlen( (const char *)buffer );
|
||||
}
|
||||
/* Retain the new line character. */
|
||||
if( p < n && retain_new_line ) {
|
||||
p++;
|
||||
n = buffer + len;
|
||||
|
||||
while( p < n && *p != '\r' && *p != '\n' ) {
|
||||
++p;
|
||||
}
|
||||
|
||||
if( p < n || finish ) {
|
||||
@ -371,11 +370,21 @@ webvtt_string_putc( webvtt_string *str, webvtt_byte to_append )
|
||||
}
|
||||
|
||||
WEBVTT_EXPORT webvtt_bool
|
||||
webvtt_string_is_equal( webvtt_string *str, webvtt_byte *to_compare, webvtt_uint len )
|
||||
webvtt_string_is_equal( const webvtt_string *str, const webvtt_byte *to_compare,
|
||||
int len )
|
||||
{
|
||||
if( !str || !to_compare || webvtt_string_length( str ) != len ) {
|
||||
if( !str || !to_compare ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if( len < 0 ) {
|
||||
len = strlen( (const char *)to_compare );
|
||||
}
|
||||
|
||||
if( str->d->length != (unsigned)len ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return memcmp( webvtt_string_text( str ), to_compare, len ) == 0;
|
||||
}
|
||||
|
||||
@ -584,8 +593,8 @@ WEBVTT_EXPORT webvtt_uint16
|
||||
webvtt_utf8_to_utf16( const webvtt_byte *utf8, const webvtt_byte *end,
|
||||
webvtt_uint16 *high_surrogate )
|
||||
{
|
||||
int need = 0, min = 0;
|
||||
webvtt_uint32 uc = 0;
|
||||
int need = 0;
|
||||
webvtt_uint32 uc = 0, min = 0;
|
||||
|
||||
/* We're missing our pointers */
|
||||
if( !utf8 ) {
|
||||
@ -625,7 +634,8 @@ webvtt_utf8_to_utf16( const webvtt_byte *utf8, const webvtt_byte *end,
|
||||
*high_surrogate = UTF_HIGH_SURROGATE( uc );
|
||||
}
|
||||
return UTF_LOW_SURROGATE( uc );
|
||||
} else if ( ( uc < min ) || ( uc >= 0xD800 && uc <= 0xDFFF ) || nc || uc >= 0x110000) {
|
||||
} else if ( ( uc < min ) || ( uc >= 0xD800 && uc <= 0xDFFF ) || nc
|
||||
|| uc >= 0x110000) {
|
||||
/* Non-character, overlong sequence, or utf16 surrogate */
|
||||
return 0xFFFD;
|
||||
} else {
|
||||
|
@ -29,10 +29,6 @@
|
||||
# define __INTERN_STRING_H__
|
||||
# include <webvtt/string.h>
|
||||
|
||||
# define UTF8_AMPERSAND (0x26)
|
||||
# define UTF8_LESS_THAN (0x3C)
|
||||
# define UTF8_GREATER_THAN (0x3E)
|
||||
# define UTF8_HYPHEN_MINUS (0x2D)
|
||||
# define UTF8_LEFT_TO_RIGHT_1 (0xE2)
|
||||
# define UTF8_LEFT_TO_RIGHT_2 (0x80)
|
||||
# define UTF8_LEFT_TO_RIGHT_3 (0x8E)
|
||||
@ -41,48 +37,6 @@
|
||||
# define UTF8_RIGHT_TO_LEFT_3 (0x8F)
|
||||
# define UTF8_NO_BREAK_SPACE_1 (0xC2)
|
||||
# define UTF8_NO_BREAK_SPACE_2 (0xA0)
|
||||
# define UTF8_NULL_BYTE (0x00)
|
||||
# define UTF8_COLON (0x3A)
|
||||
# define UTF8_SEMI_COLON (0x3B)
|
||||
# define UTF8_TAB (0x09)
|
||||
# define UTF8_FORM_FEED (0x0C)
|
||||
# define UTF8_LINE_FEED (0x0A)
|
||||
# define UTF8_CARRIAGE_RETURN (0x0D)
|
||||
# define UTF8_FULL_STOP (0x2E)
|
||||
# define UTF8_SOLIDUS (0x2F)
|
||||
# define UTF8_SPACE (0x20)
|
||||
# define UTF8_DIGIT_ZERO (0x30)
|
||||
# define UTF8_DIGIT_NINE (0x39)
|
||||
|
||||
# define UTF8_CAPITAL_A (0x41)
|
||||
# define UTF8_CAPITAL_Z (0x5A)
|
||||
|
||||
# define UTF8_A (0x61)
|
||||
# define UTF8_B (0x62)
|
||||
# define UTF8_C (0x63)
|
||||
# define UTF8_D (0x64)
|
||||
# define UTF8_E (0x65)
|
||||
# define UTF8_F (0x66)
|
||||
# define UTF8_G (0x67)
|
||||
# define UTF8_H (0x68)
|
||||
# define UTF8_I (0x69)
|
||||
# define UTF8_J (0x6A)
|
||||
# define UTF8_K (0x6B)
|
||||
# define UTF8_L (0x6C)
|
||||
# define UTF8_M (0x6D)
|
||||
# define UTF8_N (0x6E)
|
||||
# define UTF8_O (0x6F)
|
||||
# define UTF8_P (0x70)
|
||||
# define UTF8_Q (0x71)
|
||||
# define UTF8_R (0x72)
|
||||
# define UTF8_S (0x73)
|
||||
# define UTF8_T (0x74)
|
||||
# define UTF8_U (0x75)
|
||||
# define UTF8_V (0x76)
|
||||
# define UTF8_W (0x77)
|
||||
# define UTF8_X (0x78)
|
||||
# define UTF8_Y (0x79)
|
||||
# define UTF8_Z (0x7A)
|
||||
|
||||
/**
|
||||
* Taken from ICU
|
||||
@ -118,12 +72,12 @@ webvtt_string_data_t {
|
||||
static __WEBVTT_STRING_INLINE int
|
||||
webvtt_isalpha( webvtt_byte ch )
|
||||
{
|
||||
return ( ( ( ch >= UTF8_CAPITAL_A ) && ( ch <= UTF8_CAPITAL_Z ) ) || ( ( ch >= UTF8_A ) && ( ch <= UTF8_Z ) ) );
|
||||
return ( ( ( ch >= 'A' ) && ( ch <= 'Z' ) ) || ( ( ch >= 'a' ) && ( ch <= 'z' ) ) );
|
||||
}
|
||||
static __WEBVTT_STRING_INLINE int
|
||||
webvtt_isdigit( webvtt_byte ch )
|
||||
{
|
||||
return ( ( ch >= UTF8_DIGIT_ZERO ) && ( ch <= UTF8_DIGIT_NINE ) );
|
||||
return ( ( ch >= '0' ) && ( ch <= '9' ) );
|
||||
}
|
||||
|
||||
static __WEBVTT_STRING_INLINE int
|
||||
@ -135,8 +89,8 @@ webvtt_isalphanum( webvtt_byte ch )
|
||||
static __WEBVTT_STRING_INLINE int
|
||||
webvtt_iswhite( webvtt_byte ch )
|
||||
{
|
||||
return ( ( ch == UTF8_CARRIAGE_RETURN ) || ( ch == UTF8_LINE_FEED ) || ( ch == UTF8_FORM_FEED )
|
||||
|| ( ch == UTF8_TAB ) || ( ch == UTF8_SPACE ) ) ;
|
||||
return ( ( ch == '\r' ) || ( ch == '\n' ) || ( ch == '\f' )
|
||||
|| ( ch == '\t' ) || ( ch == ' ' ) ) ;
|
||||
}
|
||||
|
||||
# undef __WEBVTT_STRING_INLINE
|
||||
|
Loading…
Reference in New Issue
Block a user