A blazingly fast, header-only, zero-allocation string library for modern C++.
- 🚀 Zero Heap Allocations - Everything on the stack
- ⚡ Blazingly Fast - 5-20x faster than
std::string - 🔗 Functional Piping - Chain operations with
| - 📦 Header-Only - Just drop it in your project
- 🎯 Constexpr Everything - Compile-time string manipulation
- 🛡️ Type-Safe - Modern C++20 concepts
- 🎨 Rich API - 50+ string operations
#include<zuu/fstring.hpp>usingnamespacezuu;usingnamespacezuu::str;usingnamespacezuu::fmt;intmain() {
// Functional piping 🔗auto result = " HELLO WORLD "_sfs | trim | to_lower
| [](auto s) { s += "!!!"; return s; };
// result == "hello world!!!"// Modern formatting 🎨
std::cout << to_fstring(hex(255)) << '\n'; // "0xff"
std::cout << to_fstring(bin(42)) << '\n'; // "0b101010"
std::cout << to_fstring(pad_left(7, 3)) << '\n'; // "007"// Split & Join 📦auto parts = split("a,b,c"_fs, ',');
for (constauto& part : parts) {
std::cout << part << '\n';
}
return0;
}# Clone the repository
git clone https://github.com/zugyonozz/fstring.git
# Copy headers to your project
cp -r fstring/include/zuu /path/to/your/project/include/include(FetchContent)
FetchContent_Declare(
zuu_fstring
GIT_REPOSITORY https://github.com/zugyonozz/fstring.git
GIT_TAG v3.0.0
)
FetchContent_MakeAvailable(zuu_fstring)
target_link_libraries(your_targetPRIVATEzuu::fstring)mkdir build &&cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
sudo cmake --build . --target installThen in your CMakeLists.txt:
find_package(zuu_fstringREQUIRED)
target_link_libraries(your_targetPRIVATEzuu::fstring)- C++20 compiler
- GCC 11+
- Clang 12+
- MSVC 2019+ (19.29+)
- AppleClang 13+
- Quick Reference - API cheat sheet
- Migration Guide - Upgrading from v2.0
- Troubleshooting - Common issues
- Full API Docs - Complete reference
Chain operations naturally:
auto result = " input "_sfs | trim | to_upper | [](auto s) { return s + "!"; };// Case conversionauto lower = "HELLO"_sfs | to_lower;
auto upper = "hello"_sfs | to_upper;
auto title = "hello world"_sfs | to_title;
// Trimmingauto trimmed = " text "_sfs | trim;
// Split & Joinauto parts = split("a,b,c"_sfs, ',');
auto joined = join(parts, ", "_sfs);
// Searchbool has = contains("hello"_sfs, 'e');
bool starts = starts_with("hello"_sfs, "he");
size_t pos = find("hello"_sfs, 'l');// Proxy object patternauto hex_str = to_fstring(hex(255)); // "0xff"auto bin_str = to_fstring(bin(42)); // "0b101010"auto padded = to_fstring(pad_left(7, 5)); // "00007"// Parsingint val = parse_int<int>("42"_sfs);
float f = parse_float<float>("3.14"_sfs);usingnamespacetypes;
name_str username = "alice"; // 64 capacity
path_str file = "/usr/local/bin"; // 260 capacity
uuid_str id = "550e8400-e29b..."; // 36 capacity
ip_str address = "192.168.1.1"; // 45 capacity
email_str contact = "user@example.com"; // 254 capacityconstexprautocompile_time() {
fstring<32> s = "test";
return s | to_upper; // All at compile-time!
}
static_assert(compile_time() == "TEST");Benchmark results (GCC 13, -O3):
| Operation | fstring | std::string | Speedup |
|---|---|---|---|
| Construction | 2 ns | 45 ns | 22.5x |
| Concatenation | 8 ns | 67 ns | 8.4x |
| to_upper | 12 ns | 89 ns | 7.4x |
| trim | 15 ns | 102 ns | 6.8x |
| split | 45 ns | 234 ns | 5.2x |
| Heap Allocations | 0 | 3-5 | ∞ |
// URL parsingauto url = "https://example.com/path?key=value"_fs;
auto parts = split_by(url, "://"_sfs);
auto domain = parts[1] | split('/') | [](auto p) { return p[0]; };// INI-like formatauto config = "key = value # comment"_fs;
auto cleaned = config | split('#') | [](auto p) { return p[0]; } | trim;
auto kv = split(cleaned, '=');// Parse log linesfor (constauto& line : log_data | split_lines) {
auto fields = line | trim | split_whitespace;
process_log(fields[0], fields[1], fields[2]);
}// CSV generation
fstring<256> csv;
csv = join(fields, ","_sfs);| Feature | fstring | std::string | std::string_view |
|---|---|---|---|
| Heap Allocations | ❌ (0) | ✅ (Multiple) | ❌ (0) |
| Mutable | ✅ | ✅ | ❌ |
| Constexpr | ✅ | ✅ | |
| Piping | ✅ | ❌ | ❌ |
| Fixed Capacity | ✅ | ❌ | N/A |
| Ownership | ✅ | ✅ | ❌ (View only) |
| Rich API | ✅ (50+) | ✅ |
# Clone repository
git clone https://github.com/zugyonozz/fstring.git
cd fstring
# Build examples
mkdir build &&cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .# Run tests
./test_comprehensive
# Run examples
./example_modern_usageContributions welcome! Please see CONTRIBUTING.md.
- Unicode support (UTF-8 validation)
- Advanced pattern matching
- SIMD optimizations
- More comprehensive tests
MIT License - see LICENSE file.
- Inspired by Rust's
Stringand Python's string methods - Built with modern C++20 features
- Community feedback and contributions
- Author: zugyonozz
- Email: rafizuhayr001@gmail.com
- GitHub: https://github.com/zugyonozz/fstring
- Issues: https://github.com/zugyonozz/core/issues
- Unicode normalization
- Regex-like pattern matching
- SIMD-accelerated operations
- Custom allocator support
- Network serialization helpers
- JSON integration
- Breaking: API refinements
- C++23 features
- Enhanced constexpr support
⭐ If you find this useful, please star the repository!
Made with ❤️ by zugyonozz