Revision f9c399c4 libavformat/utils.c

View differences:

libavformat/utils.c
3707 3707
    return av_write_frame(dst, &local_pkt);
3708 3708
}
3709 3709

  
3710
void ff_parse_key_value(const char *str, ff_parse_key_val_cb callback_get_buf,
3711
                        void *context)
3712
{
3713
    const char *ptr = str;
3714

  
3715
    /* Parse key=value pairs. */
3716
    for (;;) {
3717
        const char *key;
3718
        char *dest = NULL, *dest_end;
3719
        int key_len, dest_len = 0;
3720

  
3721
        /* Skip whitespace and potential commas. */
3722
        while (*ptr && (isspace(*ptr) || *ptr == ','))
3723
            ptr++;
3724
        if (!*ptr)
3725
            break;
3726

  
3727
        key = ptr;
3728

  
3729
        if (!(ptr = strchr(key, '=')))
3730
            break;
3731
        ptr++;
3732
        key_len = ptr - key;
3733

  
3734
        callback_get_buf(context, key, key_len, &dest, &dest_len);
3735
        dest_end = dest + dest_len - 1;
3736

  
3737
        if (*ptr == '\"') {
3738
            ptr++;
3739
            while (*ptr && *ptr != '\"') {
3740
                if (*ptr == '\\') {
3741
                    if (!ptr[1])
3742
                        break;
3743
                    if (dest && dest < dest_end)
3744
                        *dest++ = ptr[1];
3745
                    ptr += 2;
3746
                } else {
3747
                    if (dest && dest < dest_end)
3748
                        *dest++ = *ptr;
3749
                    ptr++;
3750
                }
3751
            }
3752
            if (*ptr == '\"')
3753
                ptr++;
3754
        } else {
3755
            for (; *ptr && !(isspace(*ptr) || *ptr == ','); ptr++)
3756
                if (dest && dest < dest_end)
3757
                    *dest++ = *ptr;
3758
        }
3759
        if (dest)
3760
            *dest = 0;
3761
    }
3762
}
3763

  

Also available in: Unified diff