https://github.com/dimalmfao/strings
A concise collection of static string functions poorly designed to enhance efficiency in C programming tasks.
https://github.com/dimalmfao/strings
c contributions-welcome open-source
Last synced: over 1 year ago
JSON representation
A concise collection of static string functions poorly designed to enhance efficiency in C programming tasks.
- Host: GitHub
- URL: https://github.com/dimalmfao/strings
- Owner: dimalmfao
- License: gpl-3.0
- Created: 2024-02-14T07:05:50.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-08-09T14:14:19.000Z (almost 2 years ago)
- Last Synced: 2025-02-09T04:11:15.211Z (over 1 year ago)
- Topics: c, contributions-welcome, open-source
- Language: C
- Homepage:
- Size: 43 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
Awesome Lists containing this project
README
# StringsLib: Static String Library for C Programming
StringsLib is a lightweight static string library designed to simplify string manipulation tasks in C programming. This library provides a collection of functions and macros to handle common string operations efficiently.
## Features
- **Initialization:** Initialize strings from C-style strings or allocate memory for new strings.
- **Deallocation:** Free memory allocated for strings to prevent memory leaks.
- **Substrings:** Extract substrings from existing strings based on specified indices.
- **Concatenation:** Concatenate multiple strings together to create a new string.
- **Comparison:** Compare strings to determine their equality or relative order.
- **Search:** Search for a specific character within a string.
- **Tokenization:** Split strings into tokens based on a delimiter character.
- **Cross-Type Compatibility:** Functions and macros support various string input types, including `String`, `String*`, and `char*`.
## Usage
To use stringslib in your C project, follow these steps:
1. Include the `strlib.h` header file in your source files:
```c
#include "strlib.h"
```
2. Compile your project with the `strlib.c` file, which contains the implementation of stringslib functions:
```bash
gcc -o your_program your_program.c strlib.c
```
3. Start using stringslib functions and macros in your code as needed.
## Examples
### Initializing Strings
```c
String str = init_string("Hello, world!");
```
### Deallocating Strings
```c
String str = init_string("Hello, world!");
deinit_string(&str);
```
### Extracting Substrings
```c
String str = init_string("Hello, world!");
String substr = str_substring(0, 5, str);
```
### Concatenating Strings
```c
String str1 = init_string("Hello, ");
String str2 = init_string("world!");
String concatenated = str_cat(str1, str2);
```
### Comparing Strings
```c
String str1 = init_string("hello");
String str2 = init_string("world");
int result = str_compare(str1, str2);
```
### Searching for Characters
```c
String str = init_string("hello");
char* ptr = str_strchr(str, 'e');
```
### Tokenizing Strings
```c
char* input = "apple,orange,banana";
char* delim = ",";
char* token = str_tok(input, delim);
```
Feel free to contribute ;))