AceCommon
1.6.0
Arduino library for low-level common functions and features with no external dependencies
|
Provides 2 functions to perform URL form encoding and decoding. More...
#include <stdint.h>
Go to the source code of this file.
Functions | |
void | ace_common::formUrlEncode (Print &output, const char *str) |
Encode the str using an encoding suitable for GET parameters and forms in the body of a POST that expects a application/x-www-form-urlencoded type. More... | |
void | ace_common::formUrlDecode (Print &output, const char *str) |
Decode the str that was encoded using form_url_encode(). | |
void | ace_common::byteToHexChar (uint8_t c, char *high, char *low, char baseChar='A') |
Convert a byte into 2-digit, uppercase, hex. More... | |
uint8_t | ace_common::hexCharToByte (char c) |
Convert a hex character [0-9a-fA-F] into its integer value. More... | |
Provides 2 functions to perform URL form encoding and decoding.
A space ‘’ 'is converted into a
'+'`, and all other non-alphabetical characters are converted into %{hex}.
Definition in file url_encoding.h.
void ace_common::byteToHexChar | ( | uint8_t | c, |
char * | high, | ||
char * | low, | ||
char | baseChar = 'A' |
||
) |
Convert a byte into 2-digit, uppercase, hex.
For example, 0x9A returns the '9' and 'A' characters.
I tried returning the (high, low) pair as a uint16_t type, then breaking apart the 2 bytes in the calling routine. But that alternative was slower than using a reference to code0 and code1. I suspect that the compiler is able to optimize away the reference and possibly inline the entire function into the calling code.
c | the 8-bit unsigned value to be converted into hexadecimal |
high | output parameter of the high character |
low | output parameter of the low character |
baseChar | the base character of the hexadecimal range, default 'A' which returns hexadecimal characters using uppercase. Set this to 'a' to get lowercase characters. |
Definition at line 76 of file url_encoding.cpp.
void ace_common::formUrlEncode | ( | Print & | output, |
const char * | str | ||
) |
Encode the str using an encoding suitable for GET parameters and forms in the body of a POST that expects a application/x-www-form-urlencoded type.
A ' ' is converted into a '+' and non-alphanumerics are percent-encoded.
The result is printed to the output
that implements the Print
interface. The output
could be the Serial
object, but more frequently, it is useful to use an in-memory buffer such as PrintStr
. This allows us to avoid using a String object, which decreases the risk of heap fragmentation.
See https://en.wikipedia.org/wiki/Percent-encoding and https://stackoverflow.com/questions/1634271.
Definition at line 30 of file url_encoding.cpp.
uint8_t ace_common::hexCharToByte | ( | char | c | ) |
Convert a hex character [0-9a-fA-F] into its integer value.
For example, 9 returns '9', and 10 returns 'A'. Characters outside of the valid hexadecimal character range return 0.
Definition at line 83 of file url_encoding.cpp.