Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3/*
4 * This file incorporates work covered by the following copyright and
5 * permission notice:
6 *
7 * ---
8 *
9 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
10 * Copyright (C) 2012 Intel Corporation
11 *
12 * This library is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU Lesser General Public License as published by
14 * the Free Software Foundation.
15 *
16 * This library is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
19 * License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this library. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * Authors: Rodrigo Moya <rodrigo@ximian.com>
25 * Tristan Van Berkom <tristanvb@openismus.com>
26 *
27 * ---
28 */
29
36#ifndef __UTILS_STRING_H__
37#define __UTILS_STRING_H__
38
39#include <stdbool.h>
40
50int
51string_is_ascii (const char * string);
52
57char *
58string_array_contains_substr (char ** str_array, int num_str, const char * substr);
59
64bool
65string_contains_substr (const char * str, const char * substr);
66
67bool
68string_contains_substr_case_insensitive (const char * str, const char * substr);
69
77void
78string_to_upper (const char * in, char * out);
79
87void
88string_to_lower (const char * in, char * out);
89
93#define string_is_equal(str1, str2) (!g_strcmp0 (str1, str2))
94
99bool
100string_is_equal_ignore_case (const char * str1, const char * str2);
101
108NONNULL char *
109string_convert_to_filename (const char * str);
110
116MALLOC
117NONNULL char *
118string_get_substr_before_suffix (const char * str, const char * suffix);
119
125char *
126string_remove_until_after_first_match (const char * str, const char * match);
127
132void
133string_replace_regex (char ** str, const char * regex, const char * replace_str);
134
135char *
136string_replace (const char * str, const char * from, const char * to);
137
143char *
144string_get_regex_group (const char * str, const char * regex, int group);
145
154int
156 const char * str,
157 const char * regex,
158 int group,
159 int def);
160
172int
173string_get_int_after_last_space (const char * str, char * str_without_num);
174
185char **
187
195void
196string_copy_w_realloc (char ** dest, const char * src);
197
202char *
203string_symbolify (const char * in);
204
208PURE bool
209string_is_empty (const char * str);
210
220int
221string_utf8_strcasecmp (const char * s1, const char * s2);
222
226char *
227string_expand_env_vars (const char * src);
228
229void
230string_print_strv (const char * prefix, char ** strv);
231
235char **
236string_array_clone (const char ** src);
237
242#endif
char * string_get_regex_group(const char *str, const char *regex, int group)
Gets the string in the given regex group.
void string_copy_w_realloc(char **dest, const char *src)
Copies the string src to the buffer in dest after reallocating the buffer in dest to the length of sr...
void string_to_upper(const char *in, char *out)
Converts the given string to uppercase in out.
char * string_symbolify(const char *in)
Returns a new string with only ASCII alphanumeric characters and replaces the rest with underscore.
void string_replace_regex(char **str, const char *regex, const char *replace_str)
Replaces src_str with replace_str in all instances matched by regex.
MALLOC NONNULL char * string_get_substr_before_suffix(const char *str, const char *suffix)
Removes the suffix starting from suffix from full_str and returns a newly allocated string.
char ** string_array_sort_and_remove_duplicates(char **str_arr)
TODO Sorts the given string array and removes duplicates.
bool string_contains_substr(const char *str, const char *substr)
Returns if the given string contains the given substring.
char * string_expand_env_vars(const char *src)
Expands environment variables enclosed in ${} in the given string.
int string_utf8_strcasecmp(const char *s1, const char *s2)
Compares two UTF-8 strings using approximate case-insensitive ordering.
int string_get_regex_group_as_int(const char *str, const char *regex, int group, int def)
Gets the string in the given regex group as an integer.
bool string_is_equal_ignore_case(const char *str1, const char *str2)
Returns if the two strings are equal ignoring case.
int string_get_int_after_last_space(const char *str, char *str_without_num)
Returns the integer found at the end of a string like "My String 3" -> 3, or -1 if no number is found...
char ** string_array_clone(const char **src)
Clones the given string array.
int string_is_ascii(const char *string)
Returns if the string is ASCII.
char * string_remove_until_after_first_match(const char *str, const char *match)
Removes everything up to and including the first match of match from the start of the string and retu...
NONNULL char * string_convert_to_filename(const char *str)
Returns a newly allocated string that is a filename version of the given string.
PURE bool string_is_empty(const char *str)
Returns whether the string is NULL or empty.
void string_to_lower(const char *in, char *out)
Converts the given string to lowercase in out.
char * string_array_contains_substr(char **str_array, int num_str, const char *substr)
Returns the matched string if the string array contains the given substring.