StringUtilities is a header-only C++23 utility library for string handling and stream-friendly formatting of values and STL containers.
- String helpers in
include/stringutil.h:toLower,toUppertrim,trimLeft,trimRight,stripreplaceChar,replaceCharLeft,replaceCharRightsplitIntoVector,splitIntoSetscanBoolString,classifyNumberString
- Case-insensitive string and traits in
include/ci_string.h(util::ci_stringand variants). - Generic stream decoration/formatting in
include/decorator.hand conversion helpers ininclude/to_string.h(toString,toWString). - Bracket presets for formatted output in
include/brackets.h. - Customizable stream decoration for STL containers and POD types:
- Containers: Vectors, sets, maps, etc., are streamed with customizable brackets and separators.
- POD Types:
chartypes are streamed enclosed in single quotes by default (e.g.,'a').string-like types are streamed enclosed in double quotes by default (e.g.,"hello").- Numeric types can be configured for base (dec, hex, oct), width, and precision.
- System-wide Configuration: Use
util::decorator<CharT>::instance()to globally configure how types are streamed.
#include <dkyb/decorator.h>
#include <vector>
#include <iostream>
int main() {
std::vector<int> vec = {1, 2, 3};
// Default output: <1,2,3>
std::cout << vec << std::endl;
// Customizing globally
auto& deco = util::decorator<char>::instance();
deco.setBracketForKey(util::BracketKey::VECTOR, "[", " | ", "]");
// Custom output: [1 | 2 | 3]
std::cout << vec << std::endl;
}#include <dkyb/decorator.h>
#include <iostream>
int main() {
char c = 'z';
std::string s = "Zencoder";
// Default: 'z' and "Zencoder"
util::decorate(std::cout, c);
std::cout << " ";
util::decorate(std::cout, s);
std::cout << std::endl;
// Configure integer formatting (char is treated as int if configured)
auto& deco = util::decorator<char>::instance();
deco.setBase<int>(util::IntBase::hexadecimal);
deco.setShowBase<int>(true);
int val = 255;
// Output: 0xff
util::decorate(std::cout, val);
}The project uses CMake and builds tests with GoogleTest.
cmake -S . -B buildcmake --build build --parallel "$(nproc)"ctest --test-dir build --output-on-failureIf your environment does not provide a packaged GoogleTest installation, install/build GoogleTest first and make it discoverable to CMake.
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=/usr
cmake --build build --parallel "$(nproc)"
sudo cmake --install buildHeaders are installed under ${CMAKE_INSTALL_PREFIX}/include/dkyb.
- Added
cmake-commonas a submodule and migrated root build settings to shareddkyb_apply_common_settings(). - Root
CMakeLists.txtnow includesCTestand gates test directory inclusion withBUILD_TESTING. - Expanded unit-test coverage with additional tests for:
- boolean parsing
- inclusive substring bounds
- split edge-cases (empty segments, repeated separators)
- directional replacement helpers
- numeric string classification
Reduce the smells, keep on top of code-quality. Sonar Qube is run on every push to the main branch on GitHub.