-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_format.c
80 lines (73 loc) · 1.93 KB
/
ft_format.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_format.c :+: :+: */
/* +:+ */
/* By: jesmith <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/04/17 19:57:30 by aholster #+# #+# */
/* Updated: 2020/02/25 18:20:55 by aholster ######## odam.nl */
/* */
/* ************************************************************************** */
#include "./incl/ft_internals.h"
int ft_write_wrap(const char *const format,
const size_t len,
struct s_writer *const clipb)
{
if (clipb->err == 0)
{
if (clipb->self(format, len, clipb))
{
clipb->err = 1;
}
else
{
return (0);
}
}
return (-1);
}
static void ft_judex(const char *format,\
size_t *const index,\
const size_t len,\
t_writer *const clipb)
{
size_t judex;
judex = *index;
while (judex < len && format[judex] != '%')
{
judex++;
}
ft_write_wrap(format + *index, judex - *index, clipb);
*index = judex;
}
/*
** possibly add W_char or utf8 support for charskip
*/
void ft_format(const char *format,\
t_writer *const clipb)
{
size_t index;
size_t len;
t_flag flags;
index = 0;
len = ft_strlen(format);
clipb->flags = &flags;
while (index < len)
{
if (format[index] == '%')
{
index++;
ft_flagharvest(format, &index, clipb);
ft_dispatcher(format[index], clipb);
if (format[index] != '\0')
{
index++;
}
}
else
{
ft_judex(format, &index, len, clipb);
}
}
}