-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgc_parse_format_string.c
More file actions
52 lines (45 loc) · 1.6 KB
/
gc_parse_format_string.c
File metadata and controls
52 lines (45 loc) · 1.6 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
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* gc_parse_format_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gcoralie <gcoralie@student.21-school.ru +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/12 16:19:01 by gcoralie #+# #+# */
/* Updated: 2022/01/14 18:06:30 by gcoralie ### ########.fr */
/* */
/* ************************************************************************** */
#include <stddef.h>
#include "ft_printf.h"
#include "gc_libft_part.h"
static char *gc_set_flag_state(char *fs, char *conv);
char *gc_parse_format_string(char *fs, char *conv, int *symbols_printed)
{
char *res;
if (*fs == '\0')
{
*symbols_printed = 0;
return (NULL);
}
res = gc_strchr(fs, '%');
if (res == NULL)
*symbols_printed = gc_putnstr_fd(fs, 1, gc_strlen(fs), 1);
else
{
*symbols_printed = gc_putnstr_fd(fs, 1, res - fs, 1);
++res;
res = gc_set_flag_state(res, conv);
}
return (res);
}
static char *gc_set_flag_state(char *fs, char *conv)
{
char *conversion_flags;
conversion_flags = "cspdiuxX%";
if ((*fs != '\0') && (gc_strchr(conversion_flags, *fs) != NULL))
{
*conv = *fs;
++fs;
}
return (fs);
}