Utility functions for C strings.
More...
#include <stdio.h>
Go to the source code of this file.
|
|
#define | FALSE 0 |
|
#define | TRUE 1 |
|
#define | _BOOL_IS_DEFINED |
| #define | string_is_equal(a, b) |
| | Check whether two strings are equal.
|
|
| 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.
|
Utility functions for C strings.
- Author
- ByteBard
- Copyright
- MIT
cstring.h and cstring.c only support null-terminated char array.
◆ string_is_equal
| #define string_is_equal |
( |
| a, |
|
|
| b ) |
Value:
Check whether two strings are equal.
- Parameters
-
| a | The first string. |
| b | The second string. |
- Returns
- BOOL
◆ string_allocate()
| char * string_allocate |
( |
const char * | s | ) |
|
Allocate a new string out of string s.
- Parameters
-
- 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
-
- 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
-
| s | The source string. |
| from | The start index of the substring. |
| to | The 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
-
| a | The source string. |
| b | The 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
-
| a | The source string. |
| b | The 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
-
- 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
-
| a | The source string. |
| b | The target string. |
- Returns
- BOOL
◆ string_to_stream()
| FILE * string_to_stream |
( |
char * | s | ) |
|
Convert a string to a file stream.
- Parameters
-
- 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.