Пример #1
0
WBXML_DECLARE(void) wbxml_buffer_strip_blanks(WBXMLBuffer *buffer)
{
    WB_ULONG start = 0, end = 0, len = 0;
    WB_UTINY ch = 0;

    if ((buffer == NULL) || buffer->is_static)
        return;

    /* Remove whitespaces at beginning of buffer... */
    while (wbxml_buffer_get_char(buffer, start, &ch) && 
           isspace(ch) && 
           start <= wbxml_buffer_len(buffer))
    {
        start ++;
    }

    if (start > 0)
        wbxml_buffer_delete(buffer, 0, start);

    /* ... and at the end */
    if ((len = wbxml_buffer_len(buffer)) > 0) {
        end = len = len - 1;
        while (wbxml_buffer_get_char(buffer, end, &ch) &&
            isspace(ch)) 
        {
            end--;
        }
        wbxml_buffer_delete(buffer, end + 1, len - end);
    }
}
Пример #2
0
WBXML_DECLARE(void) wbxml_buffer_shrink_blanks(WBXMLBuffer *buffer)
{
    WB_ULONG i = 0, j = 0, end = 0;
    WB_UTINY ch = 0;
    
    if ((buffer == NULL) || buffer->is_static)
        return;
        
    end = wbxml_buffer_len(buffer);

    for (i = 0; i < end; i++) 
    {
        if (wbxml_buffer_get_char(buffer, i, &ch) && isspace(ch)) 
        {
            /* Replace space by a whitespace */
            if (ch != ' ')
                wbxml_buffer_set_char(buffer, i, ' ');           

            /* Remove all following spaces */
            j = i = i + 1;
            while (wbxml_buffer_get_char(buffer, j, &ch) && isspace(ch))
                j++;

            if (j - i > 1)
                wbxml_buffer_delete(buffer, i, j - i);
        }
    }
}
Пример #3
0
WBXML_DECLARE(WBXMLError) wbxml_buffer_encode_base64(WBXMLBuffer *buffer)
{
    WB_UTINY   *result = NULL;
    WBXMLError  ret    = WBXML_OK;
    
    if ( (buffer == NULL) || (buffer->is_static) ) {
        return WBXML_ERROR_INTERNAL;
    }
    
    if ((result = wbxml_base64_encode((const WB_UTINY *) wbxml_buffer_get_cstr(buffer),
                                      wbxml_buffer_len(buffer))) == NULL)
    {
        return WBXML_ERROR_B64_ENC;
    }
    
    /* Reset buffer */
    wbxml_buffer_delete(buffer, 0, wbxml_buffer_len(buffer));
    
    /* Set data */
    if (!wbxml_buffer_append_cstr(buffer, result)) {
        ret = WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }
    
    wbxml_free(result);
    
    return ret;
}
Пример #4
0
WBXML_DECLARE(WBXMLError) wbxml_buffer_decode_base64(WBXMLBuffer *buffer)
{
    WB_UTINY   *result = NULL;
    WB_LONG     len    = 0;
    WBXMLError  ret    = WBXML_OK;
    
    if ( (buffer == NULL) || (buffer->is_static) ) {
        return WBXML_ERROR_INTERNAL;
    }

    wbxml_buffer_no_spaces(buffer);
    
    if ((len = wbxml_base64_decode((const WB_UTINY *) wbxml_buffer_get_cstr(buffer),
                                   wbxml_buffer_len(buffer), &result)) <= 0)
    {
        return WBXML_ERROR_B64_DEC;
    }
    
    /* Reset buffer */
    wbxml_buffer_delete(buffer, 0, wbxml_buffer_len(buffer));
    
    /* Set binary data */
    if (!wbxml_buffer_append_data(buffer, result, len)) {
        ret = WBXML_ERROR_NOT_ENOUGH_MEMORY;
    }
    
    wbxml_free(result);
    
    return ret;
}
Пример #5
0
WBXML_DECLARE(void) wbxml_buffer_remove_trailing_zeros(WBXMLBuffer **buffer)
{
    WB_UTINY ch = 0;

    if ((buffer == NULL) || (*buffer == NULL))
        return;

    while ((*buffer)->len > 0) {
        if (wbxml_buffer_get_char(*buffer, wbxml_buffer_len(*buffer) - 1, &ch) && (ch == '\0'))
            wbxml_buffer_delete(*buffer, wbxml_buffer_len(*buffer) - 1, 1);
        else
            return;
    }
}
Пример #6
0
WBXML_DECLARE(WB_BOOL) wbxml_buffer_remove_trailing_zeros(WBXMLBuffer *buffer)
{
    WB_UTINY ch = 0;

    if ((buffer == NULL) || (buffer->is_static))
        return FALSE;

    while (buffer->len > 0) {
        if (wbxml_buffer_get_char(buffer, wbxml_buffer_len(buffer) - 1, &ch) && (ch == '\0'))
            wbxml_buffer_delete(buffer, wbxml_buffer_len(buffer) - 1, 1);
        else
            return TRUE;
    }

    return TRUE;
}
Пример #7
0
WBXML_DECLARE(void) wbxml_buffer_no_spaces(WBXMLBuffer *buffer)
{
    WB_ULONG i = 0, j = 0, end = 0;
    WB_UTINY ch = 0;
    
    if ((buffer == NULL) || buffer->is_static)
        return;
        
    while (i < wbxml_buffer_len(buffer))
    {
        if (wbxml_buffer_get_char(buffer, i, &ch) && isspace(ch)) 
        {
             wbxml_buffer_delete(buffer, i, 1);
        } else {
             i++;
        }
    }
}