clibs
Tiny but handy utility libraries for C
Loading...
Searching...
No Matches
cstring.h
Go to the documentation of this file.
1
8#ifndef CLIBS_CSTRING_H
9#define CLIBS_CSTRING_H
10
11#ifdef __cplusplus
12 #include <cstdio>
13#else
14 #include <stdio.h>
15#endif
16
17/* Custom boolean type. */
18#if _MSC_VER
19 #include <windows.h>
20#else
21#ifdef __cplusplus
22 #ifndef _BOOL_IS_DEFINED
23 typedef bool BOOL;
24 #define FALSE false
25 #define TRUE true
26 #define _BOOL_IS_DEFINED
27 #endif /* BOOL */
28#else
29 #if __STDC_VERSION__ < 199901L
30 #ifndef _BOOL_IS_DEFINED
31 typedef unsigned char BOOL;
32 #define FALSE 0
33 #define TRUE 1
34 #define _BOOL_IS_DEFINED
35 #endif /* BOOL */
36 #else
37 #ifndef _BOOL_IS_DEFINED
38 #include <stdbool.h>
39 typedef bool BOOL;
40 #define FALSE false
41 #define TRUE true
42 #define _BOOL_IS_DEFINED
43 #endif /* BOOL */
44 #endif /* C89 */
45#endif /* __cplusplus */
46#endif
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
58#define string_is_equal(a, b) (0 == strcmp((a), (b)))
59
66BOOL string_starts_with(const char *a, const char *b);
67
74BOOL string_contains(const char *a, const char *b);
75
83BOOL string_is_space_only(const char *s);
84
91char * string_allocate_char(const char c);
92
99char * string_allocate(const char *s);
100
109char * string_allocate_substring(const char *s, size_t from, size_t to);
110
118char * string_concat(const char *a, const char *b);
119
128FILE * string_to_stream(char *s);
129
130#ifdef __cplusplus
131}
132#endif
133
134#endif /* CLIBS_CSTRING_H */
char * string_concat(const char *a, const char *b)
Concat two strings and .
Definition cstring.c:153
char * string_allocate_substring(const char *s, size_t from, size_t to)
Allocate a new substring out of string s from from to to.
Definition cstring.c:124
FILE * string_to_stream(char *s)
Convert a string to a file stream.
Definition cstring.c:187
BOOL string_starts_with(const char *a, const char *b)
Check whether string a starts with string b.
Definition cstring.c:18
char * string_allocate_char(const char c)
Allocate a new string out of char c.
Definition cstring.c:84
BOOL string_contains(const char *a, const char *b)
Check whether string a contains string b.
Definition cstring.c:31
char * string_allocate(const char *s)
Allocate a new string out of string s.
Definition cstring.c:101
BOOL string_is_space_only(const char *s)
Check whether string s composes of only spaces.
Definition cstring.c:58