Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpp-strutil

Header-only C++17 string utility library. Fast, tested, zero dependencies.

Usage

#include "strutil.hpp"

// Split
auto parts = strutil::split("a,b,c", ',');        // {"a", "b", "c"}

// Join
auto csv = strutil::join(parts, ", ");             // "a, b, c"

// Trim
auto clean = strutil::trim("  hello  ");           // "hello"

// Case conversion
auto upper = strutil::to_upper("hello");           // "HELLO"

// Replace
auto fixed = strutil::replace("a-b-c", "-", "_"); // "a_b_c"

// Check prefix/suffix
strutil::starts_with("hello world", "hello");      // true
strutil::ends_with("hello world", "world");        // true

// Parse numbers
auto n = strutil::to_int("42");                    // std::optional<int>{42}

API

Function Description
split(str, delim) Split by character or string
join(parts, delim) Join with delimiter
trim(str) Trim whitespace both sides
trim_left(str) / trim_right(str) Trim one side
to_upper(str) / to_lower(str) Case conversion
starts_with(str, prefix) Prefix check
ends_with(str, suffix) Suffix check
replace(str, from, to) Replace all occurrences
pad_left(str, width) / pad_right(str, width) Padding
contains(haystack, needle) Substring check
count(str, sub) Count occurrences
slice(str, start, end?) Python-style slicing
to_int(str) / to_double(str) Safe number parsing

Build

mkdir build && cd build
cmake ..
make
make test

Quick Reference

auto s = strutil::trim("  hi  ");     // "hi"
auto v = strutil::split("a,b", ',');  // {"a","b"}
auto u = strutil::to_upper("hi");     // "HI"
bool b = strutil::starts_with(s, "x"); // false

About

No description, website, or topics provided.

Resources

Stars

6 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages