clibs
Tiny but handy utility libraries for C
Loading...
Searching...
No Matches
cstring.h File Reference

Utility functions for C strings. More...

#include <stdio.h>
Include dependency graph for cstring.h:

Go to the source code of this file.

Macros

#define FALSE   0
#define TRUE   1
#define _BOOL_IS_DEFINED
#define string_is_equal(a, b)
 Check whether two strings are equal.

Functions

BOOL string_starts_with (const char *a, const char *b)
 Check whether string a starts with string b.
BOOL string_contains (const char *a, const char *b)
 Check whether string a contains string b.
BOOL string_is_space_only (const char *s)
 Check whether string s composes of only spaces.
char * string_allocate_char (const char c)
 Allocate a new string out of char c.
char * string_allocate (const char *s)
 Allocate a new string out of string s.
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.
char * string_concat (const char *a, const char *b)
 Concat two strings and .
FILE * string_to_stream (char *s)
 Convert a string to a file stream.

Detailed Description

Utility functions for C strings.

Author
ByteBard

cstring.h and cstring.c only support null-terminated char array.

Macro Definition Documentation

◆ string_is_equal

#define string_is_equal ( a,
b )
Value:
(0 == strcmp((a), (b)))

Check whether two strings are equal.

Parameters
aThe first string.
bThe second string.
Returns
BOOL

Function Documentation

◆ string_allocate()

char * string_allocate ( const char * s)

Allocate a new string out of string s.

Parameters
sThe source string.
Returns
char *
Warning
Free the memory of the returning string by yourself.

◆ string_allocate_char()

char * string_allocate_char ( const char c)

Allocate a new string out of char c.

Parameters
cThe source char.
Returns
char *
Warning
Free the memory of the returning string by yourself.

◆ string_allocate_substring()

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.

Parameters
sThe source string.
fromThe start index of the substring.
toThe end index of the substring
Returns
char *
Warning
Free the memory of the returning string by yourself.

◆ string_concat()

char * string_concat ( const char * a,
const char * b )

Concat two strings and .

Parameters
aThe source string.
bThe source string.
Returns
char *
Warning
Free the memory of the returning string by yourself.

◆ string_contains()

BOOL string_contains ( const char * a,
const char * b )

Check whether string a contains string b.

Parameters
aThe source string.
bThe target string.
Returns
BOOL

◆ string_is_space_only()

BOOL string_is_space_only ( const char * s)

Check whether string s composes of only spaces.

Parameters
sThe source string.
Returns
BOOL

string_is_space_only will always skip end of line.

◆ string_starts_with()

BOOL string_starts_with ( const char * a,
const char * b )

Check whether string a starts with string b.

Parameters
aThe source string.
bThe target string.
Returns
BOOL

◆ string_to_stream()

FILE * string_to_stream ( char * s)

Convert a string to a file stream.

Parameters
sThe source string.
Returns
FILE *
Warning
Close the file stream by yourself.

Internally, the returning file stream is a temporary file. Due to the limitation imposed by the stdio.h on Windows, this function may fail.