Пример #1
0
WEBVTT_INTERN webvtt_status
webvtt_data_state( webvtt_byte **position, webvtt_token_state *token_state, 
                   webvtt_string *result )
{
  for ( ; *token_state == DATA; (*position)++ ) {
    switch( **position ) {
      case UTF8_AMPERSAND:
        *token_state = ESCAPE;
        break;
      case UTF8_LESS_THAN:
        if( webvtt_string_length(result) == 0 ) {
          *token_state = TAG;
        } else {
          return WEBVTT_SUCCESS;
        }
        break;
      case UTF8_NULL_BYTE:
        return WEBVTT_SUCCESS;
        break;
      default:
        CHECK_MEMORY_OP( webvtt_string_putc( result, *position[0] ) );
        break;
    }
  }

  return WEBVTT_UNFINISHED;
}
Пример #2
0
WEBVTT_INTERN webvtt_status
webvtt_node_kind_from_tag_name( webvtt_string *tag_name, webvtt_node_kind *kind )
{
  if( !tag_name || !kind ) {
    return WEBVTT_INVALID_PARAM;
  }

  if( webvtt_string_length(tag_name) == 1 ) {
    switch( webvtt_string_text(tag_name)[0] ) {
      case( UTF8_B ):
        *kind = WEBVTT_BOLD;
        break;
      case( UTF8_I ):
        *kind = WEBVTT_ITALIC;
        break;
      case( UTF8_U ):
        *kind = WEBVTT_UNDERLINE;
        break;
      case( UTF8_C ):
        *kind = WEBVTT_CLASS;
        break;
      case( UTF8_V ):
        *kind = WEBVTT_VOICE;
        break;
    }
  } else if( webvtt_string_is_equal( tag_name, "ruby", 4 ) ) {
    *kind = WEBVTT_RUBY;
  } else if( webvtt_string_is_equal( tag_name, "rt", 2 ) ) {
    *kind = WEBVTT_RUBY_TEXT;
  } else {
    return WEBVTT_INVALID_TAG_NAME;
  }

  return WEBVTT_SUCCESS;
}
Пример #3
0
Файл: cue.c Проект: caitp/webvtt
WEBVTT_EXPORT webvtt_status
webvtt_cue_validate_set_settings( webvtt_parser self, webvtt_cue *cue,
                                  const webvtt_string *settings )
{
  int line = 1;
  int column = 0;
  int length;
  const char *eol;
  int position = 0;
  webvtt_status s;
  if( !cue || !settings ) {
    return WEBVTT_INVALID_PARAM;
  }
  length = (int)webvtt_string_length( settings );
  if( ( eol = strchr( webvtt_string_text( settings ), '\r' ) )
      || ( eol = strchr( webvtt_string_text( settings ), '\n' ) ) ) {
    length = (int)( eol - webvtt_string_text( settings ) );
  }

  if( self ) {
    line = self->line;
    column = self->column;
  }

  /**
   * http://www.w3.org/html/wg/drafts/html/master/single-page.html#split-a-string-on-spaces
   * 4. Skip whitespace
   */
  column += webvtt_string_skip_whitespace( settings, &position );

  while( position < length ) {
    webvtt_string word;
    const char *keyword;
    const char *end;
    int nwhite, ncol;
    /* Collect word (sequence of non-space characters terminated by space) */
    if( WEBVTT_FAILED( webvtt_string_collect_word( settings, &word,
                       &position ) ) ) {
      return WEBVTT_OUT_OF_MEMORY;
    }
    /* skip trailing whitespace */
    nwhite = webvtt_string_skip_whitespace( settings, &position );
    /* Get the word text */
    keyword = webvtt_string_text( &word );
    /* Get pointer to end of the word. (for chcount()) */
    end = keyword + webvtt_string_length( &word );
    /* Get the column count that needs to be skipped. */
    ncol = webvtt_utf8_chcount( keyword, end );
    if( WEBVTT_FAILED( s = webvtt_cue_set_setting_from_string( cue,
                       keyword ) ) ) {
      if( self ) {
        /* Figure out which error to emit */
        webvtt_error error;
        if( webvtt_error_for_status( s, &error ) ) {
          /* There is no non-recoverable cue-setting error.
             Therefore we do not want to abort the loop, regardless
             of the return value from the error handler. */
          WARNING_AT( error, line, column );
        }
      }
    }
    /* Move column pointer beyond word and trailing whitespace */
    column += ncol + nwhite;
    webvtt_release_string( &word );
  }

  if( self ) {
    self->column = column;
  }
  return WEBVTT_SUCCESS;
}