Ejemplo n.º 1
0
WEBVTT_INTERN webvtt_status
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 ) {
      *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:
          *token_state = START_TAG_CLASS;
          break;
        case UTF8_SOLIDUS:
          *token_state = END_TAG;
          break;
        case UTF8_GREATER_THAN:
          return WEBVTT_SUCCESS;
          break;
        case UTF8_NULL_BYTE:
          return WEBVTT_SUCCESS;
          break;
        default:
          CHECK_MEMORY_OP( webvtt_string_putc( result, **position ) );
          *token_state = START_TAG;
      }
    }
  }

  return WEBVTT_UNFINISHED;
}
Ejemplo n.º 2
0
WEBVTT_INTERN webvtt_status
webvtt_tag_state( webvtt_byte **position, webvtt_token_state *token_state, 
                  webvtt_string *result )
{
  for( ; *token_state == TAG; (*position)++ ) {
    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 '.':
          *token_state = START_TAG_CLASS;
          break;
        case '/':
          *token_state = END_TAG;
          break;
        case '>':
          return WEBVTT_SUCCESS;
          break;
        case '\0':
          return WEBVTT_SUCCESS;
          break;
        default:
          CHECK_MEMORY_OP( webvtt_string_putc( result, **position ) );
          *token_state = START_TAG;
      }
    }
  }

  return WEBVTT_UNFINISHED;
}
Ejemplo n.º 3
0
Archivo: cue.c Proyecto: caitp/webvtt
WEBVTT_EXPORT webvtt_status
webvtt_cue_set_size( webvtt_cue *cue, const char *value )
{
  int digits = 0;
  webvtt_int64 number;
  const char *c;
  if( !cue || !value ) {
    return WEBVTT_INVALID_PARAM;
  }

  /**
   * 1. If value contains any characters other than U+0025 PERCENT SIGN
   * characters (%) and ASCII digits, then jump to the step labeled next
   * setting.
   */
  for( c = value; *c; ++c ) {
    if( webvtt_isdigit( *c ) ) {
      ++digits;
    } else if( *c == '%' ) {
    } else {
      return WEBVTT_BAD_SIZE;
    }
  }

  /**
   * 2. If value does not contain at least one ASCII digit, then jump to the
   * step labeled next setting.
   */
  if( !digits ) {
    return WEBVTT_BAD_SIZE;
  }

  /**
   * 3. If any character in value other than the last character is a U+0025
   * PERCENT SIGN character (%), then jump to the step labeled next setting.
   */
  if( ( c = strchr( value, '%' ) ) && ( c[1] != '\0' ) ) {
    return WEBVTT_BAD_SIZE;
  }

  /**
   * 4. If the last character in value is not a U+0025 PERCENT SIGN character
   * (%), then jump to the step labeled next setting.
   */
  if( !c ) {
    return WEBVTT_BAD_SIZE;
  }

  /**
   * 5. Ignoring the trailing percent sign, interpret value as an integer, and
   * let number be that number.
   */
  c = value;
  number = webvtt_parse_int( &c, &digits );

  /**
   * 6. If number is not in the range 0 <= number <= 100, then jump to the step
   * labeled next setting.
   */
  if( number > 100 ) {
    return WEBVTT_BAD_SIZE;
  }

  /* 7. Let cue's text track cue size be number */
  cue->settings.size = (int)number;
  if( cue->flags & CUE_HAVE_SIZE ) {
    return WEBVTT_ALREADY_SIZE;
  }
  cue->flags |= CUE_HAVE_SIZE;
  return WEBVTT_SUCCESS;
}
Ejemplo n.º 4
0
Archivo: cue.c Proyecto: caitp/webvtt
WEBVTT_EXPORT webvtt_status
webvtt_cue_set_line( webvtt_cue *cue, const char *value )
{
  webvtt_int64 number;
  int digits = 0;
  const char *c;

  if( !cue || !value ) {
    return WEBVTT_INVALID_PARAM;
  }

  /**
   * 1. If value contains any characters other than U+002D HYPHEN-MINUS
   * characters (-), U+0025 PERCENT SIGN characters (%), and ASCII digits,
   * then jump to the step labeled next setting
   */
  for( c = value; *c; ++c ) {
    if( webvtt_isdigit( *c ) ) {
      ++digits;
    } else if( *c == '-' || *c == '%' ) {
    } else {
      return WEBVTT_BAD_LINE;
    }
  }

  /**
   * 2. If value does not contain at least one ASCII digit, then jump to the
   * step labeled next setting.
   */
  if( digits == 0 ) {
    return WEBVTT_BAD_LINE;
  }

  if( strchr( value + 1, '-' ) ) {
    /**
     * 3. If any character in value other than the first character is a U+002D
     * HYPHEN-MINUS character (-), then jump to the step labeled next setting.
     */
    return WEBVTT_BAD_LINE;
  }

  if( ( c = strchr( value, '%' ) ) && ( ( c[1] != '\0' ) || *value == '-' ) ) {
    /**
     * 4. If any character in value other than the last character is a U+0025
     * PERCENT SIGN character (%), then jump to the step labeled next setting.
     *
     * 5. If the first character in value is a U+002D HYPHEN-MINUS character (-)
     * and the last character in value is a U+0025 PERCENT SIGN character (%),
     * then jump to the step labeled next setting.
     */
    return WEBVTT_BAD_LINE;
  }

  /**
   * Ignoring the trailing percent sign, if any, interpret value as a
   * (potentially signed) integer and let number be that number.
   */
  c = value;
  number = webvtt_parse_int( &c, &digits );

  if( *c == '%' ) {
    /**
     * 7. If the last character in value is a U+0025 PERCENT SIGN character (%),
     * but number is not in the range 0 < number < 100, then jump to the step
     * labeled next setting.
     */
    if( number > 100 ) {
      return WEBVTT_BAD_LINE;
    }

    /**
     * 9. If the last character in value is a U+0025 PERCENT SIGN character (%),
     * then let cue's text track cue snap-to-lines flag be false.
     */
    cue->snap_to_lines = 0;
  } else {
    /* 9. ... Otherwise, let it be true. */
    cue->snap_to_lines = 1;
  }

  /* 8. Let cue's text track cue line position be number */
  cue->settings.line = (int)number;
  if( cue->flags & CUE_HAVE_LINE ) {
    return WEBVTT_ALREADY_LINE;
  }
  cue->flags |= CUE_HAVE_LINE;
  return WEBVTT_SUCCESS;
}