aboutsummaryrefslogtreecommitdiff
path: root/c02/ex09/ft_strcapitalize.c
blob: 2707de74a9d54f1622b7cfa245e27f8e89fc45e8 (plain)
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
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_strcapitalize.c                                 :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <charles.cabergs@gmail.com>       +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2019/07/04 13:18:24 by cacharle          #+#    #+#             */
/*   Updated: 2019/07/04 15:24:18 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

int		is_between(char start, char end, char character)
{
	return (character >= start && character <= end);
}

int		is_alphanum(char character)
{
	return (is_between('a', 'z', character) || is_between('A', 'Z', character)
			|| is_between('0', '9', character));
}

char	*ft_strcapitalize(char *str)
{
	char *cursor;

	cursor = str;
	while (*cursor != '\0')
	{
		if (is_alphanum(*cursor))
		{
			if (is_between('a', 'z', *cursor))
				*cursor = *cursor - 'a' + 'A';
			cursor++;
			while (is_alphanum(*cursor))
			{
				if (is_between('A', 'Z', *cursor))
					*cursor = *cursor - 'A' + 'a';
				cursor++;
			}
		}
		cursor++;
	}
	return (str);
}