This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
/* UTF-8 character might be encoded in up to 4 bytes according to RFC | |
* 3629 so to truncate it correctly care needs to be taken for such | |
* characters. ASCII character are in single byte using 7 bits (max is | |
* 127) so any multi-byte character has first byte higher then | |
* 127. Because first byte in multi-byte sequence is encoding how many | |
* bytes this sequence has we can easily check for it looking for the | |
* first byte in sequence and see how many bytes more to truncate. |