Functions | |
std::string | htmlEncode (std::string input, bool encodeAll=false) |
std::string | htmlDecode (std::string input) |
std::string | urlEncode (std::string const &input) |
std::string | urlDecode (std::string input) |
bool | isBase64 (std::string const &input, bool allowWhitespaces=true) |
std::string | base64Encode (std::string const &input, size_t breakAfter=0, std::string const &breakSequence="") |
std::string | base64Decode (std::string const &input) |
std::string | quotedPrintableEncode (std::string const &input, std::string const &lineEnding="\r\n", bool replaceCrlf=false, bool qEncoding=false) |
std::string | quotedPrintableDecode (std::string input, bool qEncoding=false) |
std::string | makeEncodedWord (std::string const &input, bool base64=false, bool onlyIfNecessary=true) |
std::string | punycodeEncode (std::string const &input) |
std::string | punycodeDecode (std::string const &input) |
Namespace containing functions for text encoding and decoding
std::string nawa::encoding::htmlEncode | ( | std::string | input, |
bool | encodeAll = false |
||
) |
Escape special HTML characters in the input string.
input | String with characters that need to be escaped for use in HTML. |
encodeAll | If false (by default), only the characters &, ", <, and > will be escaped. If true, all characters that have an HTML entity will be encoded (less efficient and usually not necessary). Please note that if encodeAll is set to true, the input string must be utf-8 encoded for correct results. |
Definition at line 133 of file encoding.cpp.
std::string nawa::encoding::htmlDecode | ( | std::string | input | ) |
Decode a string with HTML entities by replacing them with the corresponding utf-8 characters. Only utf-8 (or ascii) encoded strings are supported by this function.
Only entities starting with & and ending in ; will be replaced, including the unicode notations. If the semicolon is missing, the entity will not be replaced.
input | Input string containing HTML entities. |
Definition at line 185 of file encoding.cpp.
std::string nawa::encoding::urlEncode | ( | std::string const & | input | ) |
Percent-encode a string for inclusion in a URL. Works with any byte-wise encoding, but only utf-8 makes sense for use in URLs.
input | String with characters that need to be escaped for use in a URL. |
Definition at line 238 of file encoding.cpp.
std::string nawa::encoding::urlDecode | ( | std::string | input | ) |
Decode a percent-encoded string (byte-wise, in URLs always utf-8).
input | Percent-encoded string. |
Definition at line 256 of file encoding.cpp.
bool nawa::encoding::isBase64 | ( | std::string const & | input, |
bool | allowWhitespaces = true |
||
) |
Check if a string contains only valid base64 characters and could be valid base64.
input | Input string. |
allowWhitespaces | If true, the whitespace characters '\r', '\n', '\t', and ' ' will be allowed. |
Definition at line 270 of file encoding.cpp.
std::string nawa::encoding::base64Encode | ( | std::string const & | input, |
size_t | breakAfter = 0 , |
||
std::string const & | breakSequence = "" |
||
) |
Encode a string (of bytes) as base64.
input | Input string. |
breakAfter | Maximum line length. The breakSequence will be inserted after the given number of base64 characters. If breakAfter is 0 (default), no line breaks will be inserted by this function. |
breakSequence | The characters to use as a line break. (e.g., "\\n" or "\\r\\n"). |
Definition at line 281 of file encoding.cpp.
std::string nawa::encoding::base64Decode | ( | std::string const & | input | ) |
Decode a base64-encoded string (of bytes). If the input string does not (only) contain valid base64, the return string may be undefined garbage. Exception: The characters '\r', '\n', '\t', and ' ' (whitespaces) will be ignored. You may use isBase64 to check it with a regex first, if the result matters.
input | Base64 representation of a string. |
Definition at line 286 of file encoding.cpp.
std::string nawa::encoding::quotedPrintableEncode | ( | std::string const & | input, |
std::string const & | lineEnding = "\r\n" , |
||
bool | replaceCrlf = false , |
||
bool | qEncoding = false |
||
) |
Encode a string using quoted-printable encoding (especially useful for emails).
input | String to be encoded. |
lineEnding | Character(s) to end the line. Default is "\\r\\n", as this is the default for emails. |
replaceCrlf | Whether to encode the '\r' and '\n' characters in the string. Defaults to false. |
qEncoding | Use the similar Q-encoding instead of quoted-printable. Line breaks will not be used, no limit on line length will be applied. |
Definition at line 290 of file encoding.cpp.
std::string nawa::encoding::quotedPrintableDecode | ( | std::string | input, |
bool | qEncoding = false |
||
) |
Decode a quoted-printable encoded string. Please note that only the line endings "\\r\\n" and "\\n" are supported.
input | Encoded string. |
qEncoding | Whether the string is Q-encoded. |
Definition at line 320 of file encoding.cpp.
std::string nawa::encoding::makeEncodedWord | ( | std::string const & | input, |
bool | base64 = false , |
||
bool | onlyIfNecessary = true |
||
) |
Convert a UTF8-encoded string to the encoded-word syntax for email headers.
input | The input string to encode. |
base64 | Whether to use base64-encoding instead of Q-encoding (defaults to false). |
onlyIfNecessary | Only apply q-encoding if special characters, which would be encoded, are present in the input (does not apply to base64 encoding). |
Definition at line 339 of file encoding.cpp.
std::string nawa::encoding::punycodeEncode | ( | std::string const & | input | ) |
Encode a domain in punycode, if it contains non-ASCII characters (otherwise it will be returned as-is). The return value of this function is undefined for invalid domain names.
input | Domain to be encoded. |
Definition at line 355 of file encoding.cpp.
std::string nawa::encoding::punycodeDecode | ( | std::string const & | input | ) |
Decode a punycode-encoded domain. If it is not encoded, it will be returned as-is. The return value of this function is undefined for invalid domain names.
input | Encoded domain. |
Definition at line 380 of file encoding.cpp.