Skip to content

zuudevs/fstring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ fstring v3.0 - Modern C++20 Fixed-Capacity String Library

C++20 License: MIT Version

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>

using namespace zuu;
using namespace zuu::str;
using namespace zuu::fmt;

int main() {
    // 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 (const auto& part : parts) {
        std::cout << part << '\n';
    }
    
    return 0;
}

πŸ“¦ 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_target PRIVATE zuu::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_fstring REQUIRED)
target_link_libraries(your_target PRIVATE zuu::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 conversion
auto lower = "HELLO"_sfs | to_lower;
auto upper = "hello"_sfs | to_upper;
auto title = "hello world"_sfs | to_title;

// Trimming
auto trimmed = "  text  "_sfs | trim;

// Split & Join
auto parts = split("a,b,c"_sfs, ',');
auto joined = join(parts, ", "_sfs);

// Search
bool has = contains("hello"_sfs, 'e');
bool starts = starts_with("hello"_sfs, "he");
size_t pos = find("hello"_sfs, 'l');

3. Modern Formatting

// Proxy object pattern
auto hex_str = to_fstring(hex(255));        // "0xff"
auto bin_str = to_fstring(bin(42));         // "0b101010"
auto padded = to_fstring(pad_left(7, 5));   // "00007"

// Parsing
int val = parse_int<int>("42"_sfs);
float f = parse_float<float>("3.14"_sfs);

4. Type-Safe Semantic Aliases

using namespace types;

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

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

static_assert(compile_time() == "TEST");

⚑ Performance

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 ∞

🎯 Use Cases

Web Development

// URL parsing
auto 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 format
auto config = "key = value # comment"_fs;
auto cleaned = config | split('#') | [](auto p) { return p[0]; } | trim;
auto kv = split(cleaned, '=');

Log Processing

// Parse log lines
for (const auto& 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

Feature fstring std::string std::string_view
Heap Allocations ❌ (0) βœ… (Multiple) ❌ (0)
Mutable βœ… βœ… ❌
Constexpr βœ… ⚠️ (Limited) βœ…
Piping βœ… ❌ ❌
Fixed Capacity βœ… ❌ N/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

Watchers

Forks

Releases

Packages

Contributors

Languages