TCString is a custom C string implementation designed for efficient memory management by utilizing a buffer size that is always the closest power of two to the actual string size. This approach optimizes memory usage and facilitates dynamic growth, making it an effective alternative to standard C string functions.
- Dynamic Buffer Management: Allocates memory with buffer sizes that are powers of two, ensuring efficient memory usage and minimizing reallocations.
- String Operations: Supports common string operations, including concatenation, substring extraction, and more.
- Inline Functions: Provides inline functions for improved performance and ease of use.
- Memory Management: Includes clear and free functions for proper memory management.
- C17 compatible compiler
- xmake build system
To use TCString, clone the repository and include TCString.h
in your project:
# Clone the repository
git clone https://github.com/yourusername/TCString.git
Include TCString.h
in your code:
#include "include/TCString.h"
You can also add TCString as a package through xmake:
add_repositories("tab-repo https://github.com/yourusername/repo-xmake.git")
add_requires("tcstring")
Then, include it in your target:
target("example")
set_kind("binary")
add_files("src/*.c")
add_packages("tcstring")
#include "TCString.h"
#include <stdio.h>
int main() {
TCString *myStr = makeTCString("Hello, ");
appendTCString(myStr, "World!");
printf("%s\n", myStr->buffer); // Output: Hello, World!
TCString *subStr = subTCString(myStr, 0, 5);
printf("%s\n", subStr->buffer); // Output: Hello
freeTCString(subStr);
freeTCString(myStr);
return 0;
}
This project uses xmake for building. To build and run tests, use the following commands:
- Ensure xmake is installed.
- Navigate to the project root directory.
- Run the following commands:
# Configure the project
xmake f -c
# Build the project
xmake
# Run the built target
xmake run MainTest
Here is the xmake.lua
configuration file used for the project:
add_rules("mode.release", "mode.debug")
add_languages("c17")
target("tcstring")
set_kind("headeronly")
add_headerfiles("include/TCString.h")
target_end()
target("MainTest")
set_kind("binary")
add_files("src/main.c")
add_deps("tcstring")
add_includedirs("include")
target_end()
TCString/
├── include/
│ └── TCString.h
├── src/
│ └── main.c
├── xmake.lua
└── README.md
Contributions are welcome! If you have ideas for improving TCString, feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.