-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_putwchar.c
More file actions
executable file
·48 lines (44 loc) · 1.56 KB
/
ft_putwchar.c
File metadata and controls
executable file
·48 lines (44 loc) · 1.56 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putwchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cmukwind <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/08/19 09:39:37 by cmukwind #+# #+# */
/* Updated: 2018/08/23 08:52:34 by cmukwind ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
inline static int size_wchar(unsigned int wchar)
{
if (wchar <= 127)
return (1);
else if (wchar >= 128 && wchar <= 2047)
return (2);
else if (wchar >= 2048 && wchar <= 65535)
return (3);
else if (wchar >= 65536 && wchar <= 2097151)
return (4);
else
return (0);
}
int ft_putwchar(wchar_t wchar)
{
char res;
char size;
unsigned char curr_byte;
res = 0;
size = size_wchar(wchar);
if (size == 1)
return (ft_putchar(wchar));
curr_byte = (260 << (4 - size)) | (wchar >> ((size - 1) * 6));
res += ft_putchar(curr_byte);
size--;
while (size--)
{
curr_byte = ((wchar >> ((size) * 6)) & 63) | 128;
res += ft_putchar(curr_byte);
}
return (res);
}