Allows for processing of, replacement of malformed characters, and conversion between UTF-8, UTF-16, and UTF-32 string encodings.
Being a Windows utility library, also comes with some helper functions to display UTF-8 instead of mojibake in the CMD prompt.
Have you ever seen the true face of 『🆆🅸🅽🅳🅾🆆🆂』, exile?
- Get the condensed header file from the Releases tab.
- Add the file to your C project.
- Functionality is exposed through the ReencoderUnicodeStruct struct.
- To initialise a struct, use the following:
ReencoderUnicodeStruct* reencoder_utf8_parse(const uint8_t* string);
ReencoderUnicodeStruct* reencoder_utf16_parse_uint16(const uint16_t* string, enum ReencoderEncodeType target_endian);
ReencoderUnicodeStruct* reencoder_utf16_parse_uint8(const uint8_t* string, size_t bytes, enum ReencoderEncodeType source_endian, enum ReencoderEncodeType target_endian);
ReencoderUnicodeStruct* reencoder_utf32_parse_uint32(const uint32_t* string, enum ReencoderEncodeType target_endian);
ReencoderUnicodeStruct* reencoder_utf32_parse_uint8(const uint8_t* string, size_t bytes, enum ReencoderEncodeType source_endian, enum ReencoderEncodeType target_endian);- To repair a struct containing a malformed string, use:
unsigned int reencoder_repair_struct(ReencoderUnicodeStruct* unicode_struct);- To initialise a struct with a different encode type, use:
ReencoderUnicodeStruct* reencoder_convert(enum ReencoderEncodeType source_encoding, enum ReencoderEncodeType target_encoding, const void* source_uint_buffer);- To get more details about a struct's contents, use the following:
const char* reencoder_encode_type_as_str(unsigned int encode_type);
const char* reencoder_outcome_as_str(unsigned int outcome);- To make use of the string contents in a struct, use the following:
size_t reencoder_write_to_buffer(ReencoderUnicodeStruct* unicode_struct, uint8_t* target_buffer, unsigned int write_bom);
size_t reencoder_write_to_file(ReencoderUnicodeStruct* unicode_struct, FILE* file_pointer, unsigned int write_bom);- To duplicate or free a struct, use the following:
ReencoderUnicodeStruct* reencoder_unicode_struct_duplicate(ReencoderUnicodeStruct* unicode_struct);
void reencoder_unicode_struct_free(ReencoderUnicodeStruct** unicode_struct);- To prevent Windows mojibake, use the following:
void reencoder_locale_init_utf8();
void reencoder_locale_deinit();More detailed usage instructions can be found in the header file or the online docs [which doesn't exist yet... :( ].
(🛠️) website docs soon?
This project uses Consolidator as a submodule.
git clone --recurse-submodules https://github.com/maximus-lee-678/reenCoder.git- Get latest vcpkg zip file and extract it.
- Open Developer Command Prompt for VS and cd to wherever vckpg has been extracted to.
- Run:
bootstrap-vcpkg.bat- Run:
vcpkg.exe integrate install- Run:
vcpkg.exe install cmockaOR
vcpkg.exe install cmocka --triplet=x64- After installation, in the project: ensure solution configuration (next to debug buttons) is targeting right triplet (x86 or x64).