O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
map.c
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
8/* Copyright 2023, SAFRAN T4DS, ALL RIGHTS RESERVED */
9/* */
10/* @file map.c */
11/* @author Antoine GAGNIERE */
12/* */
13/* ************************************************************************** */
14
15#include "o2s/string.h"
16
17#include <ctype.h> // tolower, toupper
18
23string_t string_map(const string_t* self, char (*function)(char))
24{
25 string_t result = string_new();
26 char c;
27
28 string_reserve(&result, string_length(self));
29 string_foreach(self, &c)
30 {
31 string_append_char(&result, function(c));
32 }
33 return result;
34}
35
36#pragma GCC diagnostic push
37#pragma GCC diagnostic ignored "-Wcast-function-type"
38
40string_t string_tolower(const string_t* self)
41{
42 return string_map(self, (char (*)(char))tolower);
43}
44
46string_t string_toupper(const string_t* self)
47{
48 return string_map(self, (char (*)(char))toupper);
49}
50
51#pragma GCC diagnostic pop
Dynamic string implementation.
#define string_foreach(STRING, Element)
Iterate over each character of the string.
Definition string.h:126
string_t string_new(void)
Constructs an empty string.
array_t string_t
A string is an array of char.
Definition string.h:30