URLEncodeString

Offers interface to encode/decode strings format suitable for URLs.

Summary
URLEncodeStringOffers interface to encode/decode strings format suitable for URLs.
CopyrightThis program is free software.
Files
C-kern/api/string/urlencode_string.hHeader file URLEncodeString.
C-kern/string/urlencode_string.cImplementation file URLEncodeString impl.
URLEncoding.All functions assumes that strings are utf8 encoded.
Functions
test
unittest_string_urlencodeTest url encoding/decoding of strings.
string_t
query
sizeurlencode_stringDetermines url encoded length of parameter str.
sizeurldecode_stringDetermines url decoded length of parameter str.
urlencoding
urlencode_stringEncodes string str to url encoding.
urldecode_stringDecodes a URL encoded string.

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/string/urlencode_string.h

Header file URLEncodeString.

C-kern/string/urlencode_string.c

Implementation file URLEncodeString impl.

URLEncoding.

All functions assumes that strings are utf8 encoded.

Functions

Summary
test
unittest_string_urlencodeTest url encoding/decoding of strings.

test

unittest_string_urlencode

int unittest_string_urlencode(void)

Test url encoding/decoding of strings.

string_t

Summary
query
sizeurlencode_stringDetermines url encoded length of parameter str.
sizeurldecode_stringDetermines url decoded length of parameter str.
urlencoding
urlencode_stringEncodes string str to url encoding.
urldecode_stringDecodes a URL encoded string.

query

sizeurlencode_string

size_t sizeurlencode_string(const struct string_t *str,
uint8_t except_char)

Determines url encoded length of parameter str.

Set except_char to ‘/’ if the path of a URL is to be encoded.  Set except_char to ‘ ‘ if a formdata field is to be encoded.

sizeurldecode_string

size_t sizeurldecode_string(const struct string_t *str)

Determines url decoded length of parameter str.

urlencoding

urlencode_string

int urlencode_string(const struct string_t *str,
uint8_t except_char,
uint8_t changeto_char,
/*ret*/struct wbuffer_t *result)

Encodes string str to url encoding.  URL encoding assumes utf8 or ascii encoded strings.  Every octet is encoded individually.  Alphanumeric characters (“A-Z”, “a-z”, “0-9”) are not changed and directly written to the output.  Character codes which are neither alphanumeric nor one of “-_.*” are written as triplet of ‘%’ plus two hexadecimal digits.

If parameter except_char is set to 0 no exception is made during encoding.  If it is set to a value != 0 the character is not encoded but changed into the character given in parameter changeto_char.

Set except_char to ‘/’ and changeto_char to ‘/’ if the path of a URL is to be encoded cause ‘/’ is considered a normal character for a path.

Set except_char to ‘ ‘ and changeto_char to ‘+’ if a formdata field is to be encoded.

urldecode_string

int urldecode_string(const struct string_t *str,
uint8_t changefrom_char,
uint8_t changeinto_char,
/*ret*/struct wbuffer_t *result)

Decodes a URL encoded string.  The decoded string is equal or smaller in size.

Set parameter changefrom_char to value ‘+’ and changeinto_char to value ‘ ‘ in case a formdata field is decoded.

Else set changefrom_char to 0 so no character is changed therefore changeinto_char is never used.

Offers interface to encode/decode strings format suitable for URLs.
Implements URLEncodeString.
int unittest_string_urlencode(void)
Test url encoding/decoding of strings.
size_t sizeurlencode_string(const struct string_t *str,
uint8_t except_char)
Determines url encoded length of parameter str.
size_t sizeurldecode_string(const struct string_t *str)
Determines url decoded length of parameter str.
int urlencode_string(const struct string_t *str,
uint8_t except_char,
uint8_t changeto_char,
/*ret*/struct wbuffer_t *result)
Encodes string str to url encoding.
int urldecode_string(const struct string_t *str,
uint8_t changefrom_char,
uint8_t changeinto_char,
/*ret*/struct wbuffer_t *result)
Decodes a URL encoded string.
Close