diff options
| author | 2024-01-13 17:45:42 +0000 | |
|---|---|---|
| committer | 2024-01-13 17:45:42 +0000 | |
| commit | 0086b162aa6c4b4f9ed98ff7c9f2f31dbe039944 (patch) | |
| tree | f6be9230e8f28ce1371b3a2a0dc9570e6a00c09d /include/stringutils.h | |
| parent | Fix the string overload of Hex::Encode not passing on the separator. (diff) | |
Add Hex::Decode as a complement for Hex::Encode.
Diffstat (limited to 'include/stringutils.h')
| -rw-r--r-- | include/stringutils.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/include/stringutils.h b/include/stringutils.h index 7032ea75f..854b62647 100644 --- a/include/stringutils.h +++ b/include/stringutils.h @@ -79,6 +79,26 @@ namespace Hex /** The table used for encoding as an upper-case hexadecimal string. */ inline constexpr const char* TABLE_UPPER = "0123456789ABCDEF"; + /** Decodes a hexadecimal-encoded byte array. + * @param data The byte array to decode from. + * @param length The length of the byte array. + * @param separator If non-zero then the character hexadecimal digits are separated with. + * @param table The index table to use for decoding. + * @return The decoded form of the specified data. + */ + CoreExport std::string Decode(const void* data, size_t length, const char* table = nullptr, char separator = 0); + + /** Decodes a hexadecimal-encoded string. + * @param data The string to decode from. + * @param table The index table to use for decoding. + * @param separator If non-zero then the character hexadecimal digits are separated with. + * @return The decoded form of the specified data. + */ + inline std::string Decode(const std::string& data, const char* table = nullptr, char separator = 0) + { + return Decode(data.c_str(), data.length(), table, separator); + } + /** Encodes a byte array using hexadecimal encoding. * @param data The byte array to encode from. * @param length The length of the byte array. |
