forked from scanoss/wayuu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_utils.h
More file actions
88 lines (78 loc) · 2.71 KB
/
string_utils.h
File metadata and controls
88 lines (78 loc) · 2.71 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2018-2020 SCANOSS LTD
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef __WAYUU_STRING_UTILS_H
#define __WAYUU_STRING_UTILS_H
#include <stdbool.h>
/**
* MAX_INT_STR: Defines the maximum length of a string representation of an integer.
*/
#define MAX_INT_STR 32
/**
* MAX_SPLIT_STR: Maximum number of strings that can be handled by split method.
*/
#define MAX_SPLIT_STR 50
#define MAX_SPLIT_STR_LEN 1024
typedef struct str_list_t
{
int n_str;
char *strings[MAX_SPLIT_STR];
} str_list_t;
/**
* md5sum: Returns a hex representation of the MD5 of the input 'data' string.
*/
void md5sum(char *out, char *data, int len);
void trim(char *str);
/**
* rtrim: Returns a subtring of the original string until the first occurrence of the character 'sep'.
*/
char *rtrim(const char *str, char sep);
str_list_t *split(char *str, char *delim);
void free_str_list_t(str_list_t *list);
/**
* split_once: Variant of split, only splits at most once the string by the separator.
*/
str_list_t *split_once(char *str, char *delim);
/*
* join: returns a dynamically allocated string with all the elements separated by the delimiter specified.
*/
char *join(char **array, int size, char *delim);
/**
* startswithany: Checks if any of the strings in the list is contained in the string and returns true
* otherwise it returns false.
*
* IMPORTANT: list has to be an array of strings with the last element an empty string, "". This saves having to add
* an extra argument with the size of the array.
*/
bool startswithany(char *str, const char *list[]);
/**
* startswith: Returns true if str starts with prefix.
*/
bool startswith(char *str, const char *prefix);
/**
* chop_string: Chops string at the next character less than 34 ASCII ('"')
*/
void chop_string(char *input);
/**
* text_find_after: Returns position in haystack right after end of needle, or -1 if not found
*/
long text_find_after(char *haystack, char *needle, long start, long bytes);
/**
* string_isalnum: Returns true if the whole string is a valid alphanumeric string.
*/
bool string_isalnum(char *data);
#endif