MCPcopy Create free account
hub / github.com/NetHack/NetHack / unicodeval_to_utf8str

Function unicodeval_to_utf8str

src/hacklib.c:877–919  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

875}
876
877RESTORE_WARNING_FORMAT_NONLITERAL
878
879/* Unicode routines */
880
881int
882unicodeval_to_utf8str(int uval, uint8 *buffer, size_t bufsz)
883{
884 // static uint8 buffer[7];
885 uint8 *b = buffer;
886
887 if (bufsz < 5)
888 return 0;
889 /*
890 * Binary Hex Comments
891 * 0xxxxxxx 0x00..0x7F Only byte of a 1-byte character encoding
892 * 10xxxxxx 0x80..0xBF Continuation byte : one of 1-3 bytes following
893 * first 110xxxxx 0xC0..0xDF First byte of a 2-byte character encoding
894 * 1110xxxx 0xE0..0xEF First byte of a 3-byte character encoding
895 * 11110xxx 0xF0..0xF7 First byte of a 4-byte character encoding
896 */
897 *b = '\0';
898 if (uval < 0x80) {
899 *b++ = uval;
900 } else if (uval < 0x800) {
901 *b++ = 192 + uval / 64;
902 *b++ = 128 + uval % 64;
903 } else if (uval - 0xd800u < 0x800) {
904 return 0;
905 } else if (uval < 0x10000) {
906 *b++ = 224 + uval / 4096;
907 *b++ = 128 + uval / 64 % 64;
908 *b++ = 128 + uval % 64;
909 } else if (uval < 0x110000) {
910 *b++ = 240 + uval / 262144;
911 *b++ = 128 + uval / 4096 % 64;
912 *b++ = 128 + uval / 64 % 64;
913 *b++ = 128 + uval % 64;
914 } else {
915 return 0;
916 }
917 *b = '\0'; /* NUL terminate */
918 return 1;
919}
920
921int
922case_insensitive_comp(const char *s1, const char *s2)

Callers 2

to_unicode_callbackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected