A minimal C string library offering dynamic memory-safe operations like insert, concat, trim, join, and split, designed for low-footprint environments.
Brin is a lightweight, efficient, and safe C string library designed to provide common string operations while ensuring memory safety through dynamic allocation management. It is ideal for embedded or resource-constrained systems where performance and memory footprint matter.
- Dynamic, memory-safe string manipulation
- String insertion and concatenation with automatic resizing
- Substring search and equality comparison
- Whitespace trimming (start, end, or both)
- Case conversion (to lower and upper)
- Checks for emptiness and whitespace-only content
- Split and Join
- Standard mode (default): Uses function pointers within the Brin struct to allow method-like syntax (b.concat(&b, suffix)).
- BRIN_LITE mode: Compile with -DBRIN_LITE to disable function pointers inside the struct, reducing memory overhead. Functions remain fully usable but must be called directly (brin_concat(&b, suffix)).
You can use the following make commands to build, test, install, and format the library:
| make | Compiles the static library libbrin.a from brin.o |
| make test | Builds and runs test.c linked against libbrin.a |
| make BRIN_LITE=1 | Compiles test.c in BRIN_LITE mode (disables function pointers) |
| make install | Installs brin.h to ${PREFIX}/include and libbrin.a to ${PREFIX}/lib |
| make uninstall | Removes installed brin.h and libbrin.a |
| make format | Formats all .c and .h files using astyle with a consistent style |
| make clean | Cleans all build artifacts: object files, static library, and test binary |
Default install prefix is /usr/local. You can override it via make install PREFIX=/your/path.
All examples work in both standard and BRIN_LITE modes by changing the call syntax.
Creates a new Brin string initialized with the provided text.
Inserts a string at a given index.
Concatenates a string to the end.
Checks if the string contains a given substring.
Returns the index of the first occurrence of the substring.
Checks if the string equals another string.
Checks if the string is empty.
Checks if the string only contains whitespace.
Converts the string to uppercase.
Converts the string to lowercase.
Trims leading whitespace.
Trims trailing whitespace.
Trims both leading and trailing whitespace.
Joins an array of strings with a separator.
Splits the string into an array of strings using a delimiter.
Frees the memory used by the Brin string.
Removes a portion of the string between the start (inclusive) and end (exclusive) indices.
Replaces all occurrences of a substring with another string.
- Minimal and focused: Small codebase tailored for constrained environments.
- Memory-safe: Prevents null pointer and memory allocation errors.
- Flexible: Choose between method-like calls or direct function usage via the BRIN_LITE flag.
- Versatile: Covers essential string operations without heavy dependencies.
MIT License
.png)
