Skip to content

Repository files navigation

🚀 fstring v3.0 - Modern C++20 Fixed-Capacity String Library

C++20License: MITVersion

A blazingly fast, header-only, zero-allocation string library for modern C++.

✨ Features

  • 🚀 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

🎯 Quick Example

#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;
}

📦 Installation

Method 1: Header-Only (Recommended)

# 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/

Method 2: CMake FetchContent

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)

Method 3: System Install

mkdir build &&cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local
sudo cmake --build . --target install

Then in your CMakeLists.txt:

find_package(zuu_fstringREQUIRED)
target_link_libraries(your_targetPRIVATEzuu::fstring)

🔧 Requirements

  • C++20 compiler
    • GCC 11+
    • Clang 12+
    • MSVC 2019+ (19.29+)
    • AppleClang 13+

📚 Documentation

🎨 Core Features

1. Functional Piping

Chain operations naturally:

auto result = " input "_sfs | trim | to_upper | [](auto s) { return s + "!"; };

2. Rich String Algorithms

// 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');

3. Modern Formatting

// 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);

4. Type-Safe Semantic Aliases

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 capacity

5. Constexpr Everything

constexprautocompile_time() {
fstring<32> s = "test";
return s | to_upper; // All at compile-time!
}
static_assert(compile_time() == "TEST");

⚡ Performance

Benchmark results (GCC 13, -O3):

Operationfstringstd::stringSpeedup
Construction2 ns45 ns22.5x
Concatenation8 ns67 ns8.4x
to_upper12 ns89 ns7.4x
trim15 ns102 ns6.8x
split45 ns234 ns5.2x
Heap Allocations03-5

🎯 Use Cases

Web Development

// 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]; };

Configuration Parsing

// INI-like formatauto config = "key = value # comment"_fs;
auto cleaned = config | split('#') | [](auto p) { return p[0]; } | trim;
auto kv = split(cleaned, '=');

Log Processing

// Parse log linesfor (constauto& line : log_data | split_lines) {
auto fields = line | trim | split_whitespace;
process_log(fields[0], fields[1], fields[2]);
}

Data Serialization

// CSV generation
fstring<256> csv;
csv = join(fields, ","_sfs);

📊 Comparison

Featurefstringstd::stringstd::string_view
Heap Allocations❌ (0)✅ (Multiple)❌ (0)
Mutable
Constexpr⚠️ (Limited)
Piping
Fixed CapacityN/A
Ownership❌ (View only)
Rich API✅ (50+)⚠️ (Limited)

🛠️ Building & Testing

# 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_usage

🤝 Contributing

Contributions welcome! Please see CONTRIBUTING.md.

Areas Needing Help

  • Unicode support (UTF-8 validation)
  • Advanced pattern matching
  • SIMD optimizations
  • More comprehensive tests

📜 License

MIT License - see LICENSE file.

🙏 Acknowledgments

  • Inspired by Rust's String and Python's string methods
  • Built with modern C++20 features
  • Community feedback and contributions

📞 Contact

🗺️ Roadmap

v3.1 (Q1 2026)

  • Unicode normalization
  • Regex-like pattern matching
  • SIMD-accelerated operations

v3.2 (Q2 2026)

  • Custom allocator support
  • Network serialization helpers
  • JSON integration

v4.0 (Q3 2026)

  • Breaking: API refinements
  • C++23 features
  • Enhanced constexpr support

⭐ If you find this useful, please star the repository!

Made with ❤️ by zugyonozz

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages