-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printf_unicode.c
More file actions
49 lines (46 loc) · 1.58 KB
/
ft_printf_unicode.c
File metadata and controls
49 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_unicode.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mfrisby <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/07/11 13:15:21 by mfrisby #+# #+# */
/* Updated: 2017/07/11 13:15:22 by mfrisby ### ########.fr */
/* */
/* ************************************************************************** */
#include "libftprintf.h"
static void ft_printf_uni2(unsigned char *const buf, const unsigned int code)
{
buf[0] = 0xF0 | (code >> 18);
buf[1] = 0x80 | ((code >> 12) & 0x3F);
buf[2] = 0x80 | ((code >> 6) & 0x3F);
buf[3] = 0x80 | (code & 0x3F);
}
size_t ft_printf_unicode(unsigned char *const buf, const unsigned int code)
{
if (code <= 127)
{
buf[0] = code;
return (1);
}
if (code <= 0x7FF)
{
buf[0] = 0xC0 | (code >> 6);
buf[1] = 0x80 | (code & 0x3F);
return (2);
}
if (code <= 0xFFFF)
{
buf[0] = 0xE0 | (code >> 12);
buf[1] = 0x80 | ((code >> 6) & 0x3F);
buf[2] = 0x80 | (code & 0x3F);
return (3);
}
if (code <= 0x10FFFF)
{
ft_printf_uni2(buf, code);
return (4);
}
return (0);
}