-
Notifications
You must be signed in to change notification settings - Fork 1
/
handle_char.c
51 lines (45 loc) · 1.31 KB
/
handle_char.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
#include "main.h"
/**
* handle_char - appends a character to the string buffer
* @args: arguments list
* @buffer: string buffer to store the result
* @spec: pointer to a format specifier
*
* Return: 1, the character appended to the string buffer
*/
int handle_char(const format_specifier *spec, va_list args,
string_buffer *buffer)
{
int characters_added;
size_t initial_length;
char ch = va_arg(args, int);
initial_length = buffer->length;
/* handle space padding before the character */
if (spec->width && !spec->minus_flag)
{
handle_width((format_specifier *)spec, buffer, 1);
}
append_char(buffer, ch);
/* handle the space padding after character */
if (spec->minus_flag)
{
handle_width((format_specifier *)spec, buffer, 1);
}
characters_added = buffer->length - initial_length;
return (characters_added);
}
/**
* handle_percent - appends the percentage to the string buffer
* @args: arguments list
* @buffer: string buffer to store the result
* @spec: pointer to a format specifier
*
* Return: Returns the number 1, indicating that
* a single percent character '%' has been appended to the string buffer
*/
int handle_percent(__attribute__((unused)) const format_specifier *spec,
__attribute__((unused)) va_list args, string_buffer *buffer)
{
append_char(buffer, '%');
return (1);
}