safestring! is a C++ library that provides safer alternatives to traditional string manipulation functions. It incorporates bounds checking and automatic memory management to prevent vulnerabilities such as buffer overflows.
- Concatenation: Combine strings safely without manual memory management.
- Substring Extraction: Extract substrings with bounds checking.
- Splitting: Split strings into components based on delimiters.
- Replacing: Replace substrings with automatic error handling.
- Formatting: Type-safe string formatting.
- Utility Functions: Additional tools for trimming, padding, and case conversion.
SafeString/
├── CMakeLists.txt # Top-level CMake file
├── src/ # Library source and headers
│ ├── SafeString.cpp # Show case implementation
├── src/ # Library source and headers
│ ├── SafeString.h # Header file
├── tests/ # Unit tests
│ ├── CMakeLists.txt # CMake configuration for tests
│ └── TestSafeString.cpp # Test cases
└── build/ # Build directory (generated by CMake)
- Clone the repository:
git clone https://github.com/your-username/SafeString.git
cd SafeString- Create a build directory and navigate to it:
mkdir build && cd build- Run CMake to configure the project:
cmake ..- Build the project:
cmake --build .If you enabled BUILD_TESTS, you can run the unit tests:
- Use
ctestin thebuilddirectory:
ctest- Alternatively, run the test executable directly:
./tests/TestSafeString
#include "SafeString/SafeString.h"#include "SafeString/SafeString.h"
#include <iostream>
int main() {
std::string result = SafeString::concatenate("Hello, ", "World!");
std::cout << result << std::endl; // Outputs: Hello, World!
return 0;
}std::string part = SafeString::safeSubstring("Hello, World!", 7, 5);
// Result: "World"std::vector<std::string> tokens = SafeString::split("A,B,C", ',');
// Result: {"A", "B", "C"}