Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

decode urlencoded string

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • decode urlencoded string

    ' original C function by Gerhard Smith.
    '//does an inplace urlunencode
    'INT CClientSocket::URLUnEncode(char *str) {
    ' char *p = str;
    ' char tab[32] = {0x00, 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
    ' 0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    ' 0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };
    ' FOR ( ;*p != 0x00; p++) {
    ' IF (*p == '%' && *(p+1) != '%') {
    ' p++;
    ' *str = ((tab[(*p)-48] << 4) + tab[(*(p+1))-48]);
    ' p++;
    ' str++;
    ' continue;
    ' }
    ' *str = *p;
    ' str++;
    ' }
    ' *str = 0x00;
    'RETURN(0);
    '}
    '
    FUNCTION URLUnEncode( url AS STRING) AS STRING
    LOCAL pbByte AS BYTE PTR
    LOCAL pbUrl AS BYTE PTR
    LOCAL pbTable AS BYTE PTR
    LOCAL b1 AS BYTE
    STATIC table AS STRING
    LOCAL pszReturnStr AS ASCIIZ PTR
    IF table="" THEN
    table=table+CHR$(0)+CHR$(1)+CHR$(2)+CHR$(3)+CHR$(4)+CHR$(5)+CHR$(6)+CHR$(7)+CHR$(8)+CHR$(9)
    table=table+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)+CHR$(0)
    table=table+CHR$(10)+CHR$(11)+CHR$(12)+CHR$(13)+CHR$(14)+CHR$(15)+CHR$(16)
    END IF
    pbByte = STRPTR( url )
    pbUrl = STRPTR( url )
    pbTable = STRPTR(table)
    DO WHILE @pbByte <> 0
    IF @pbByte = ASC("%") AND NOT @pbByte[1] = ASC("%") THEN
    INCR pbByte
    b1 = @pbTable[@pbByte-48]
    SHIFT LEFT b1,4
    INCR pbByte
    @pbUrl= @pbTable[@pbByte-48]+b1
    INCR pbByte
    INCR pbUrl
    ITERATE DO
    END IF
    @pbUrl = @pbByte
    INCR pbByte
    INCR pbUrl
    LOOP
    @pbUrl = 0
    pszReturnStr = STRPTR( url )
    FUNCTION = @pszReturnStr
    END FUNCTION
    Alban
Working...
X