-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdh_string_util.h
More file actions
97 lines (83 loc) · 3.56 KB
/
dh_string_util.h
File metadata and controls
97 lines (83 loc) · 3.56 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
89
90
91
92
93
94
95
96
97
/* dh_string_util - String utils by Dream Helium
Copyright (C) 2022 Dream Helium
This file is part of litematica_reader_c.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#ifndef DH_STRING_UTIL_H
#define DH_STRING_UTIL_H
#include <glib.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct DhStrArray DhStrArray;
typedef struct DhString DhString;
char *dh_strdup (const char *o_str);
char *dh_str_array_cat (DhStrArray *arr); /* malloc'd */
char *dh_str_array_cat_with_split (DhStrArray *arr, const char *split);
DhStrArray *dh_str_array_init (const char *str);
int dh_str_array_add_str (DhStrArray **arr, const char *str);
DhStrArray *dh_str_array_dup (DhStrArray *arr);
gboolean dh_str_array_find_repeated (DhStrArray *arr, const char *str);
gboolean dh_str_array_equal (const DhStrArray *arr1,
const DhStrArray *arr2,
gboolean ignore_order);
int dh_str_array_find (DhStrArray *arr, const char *str);
void dh_str_array_remove (DhStrArray **arr, const char *str);
guint dh_str_array_find_char (DhStrArray *arr, char key);
int *dh_str_array_find_include_chars (DhStrArray *arr, char *key,
int *len);
void dh_str_array_free (DhStrArray *arr);
char **dh_str_array_dup_to_plain (DhStrArray *arr); /* malloc'd */
void dh_str_array_free_plain (char **strv);
DhStrArray *dh_str_array_cat_str_array (DhStrArray *arr1, DhStrArray *arr2,
const char *split);
gboolean dh_str_find_char (const char *str, char find_char);
DhString *dh_string_new_with_string (const char *str);
void dh_string_free (DhString *str);
void dh_string_replace_internal_string (DhString *string, const char *str);
void dh_string_add_arg (DhString *string, const char *arg);
void dh_string_replace_with_args (DhString *string);
/* Temp string until you free `DhString` */
char *dh_string_get_string (DhString *string);
char *dh_get_filename_without_extension (const char *filename);
/** Use dh_getdelim */
int dh_getline (char **input, size_t *n, FILE *stream);
#define dh_string_getline(input, n, stream) dh_getline (input, n, stream)
int dh_getdelim (char **input, size_t *n, int delim, FILE *stream);
/* Might not accurate, and if not UTF-8, return -1 */
int dh_getprintlen (const char *str);
int *dh_getprint_singlelen (const char *str, int *size);
char *dh_getprint_str (const char *str, int printlen);
typedef struct DhStrArray
{
char **val;
int num;
#ifdef __cplusplus
const char *
operator[] (int i) const
{
if (i < num)
return val[i];
return nullptr;
}
int
operator* () const
{
return num;
}
#endif
} DhStrArray;
#ifdef __cplusplus
}
#endif
#endif // DH_STRING_UTIL_H