Skip to content

A small, efficient C library providing missing utilities for safe and comfortable string manipulation and time helpers. Designed to be lightweight, portable, and easy to integrate into C projects.

License

Notifications You must be signed in to change notification settings

murapadev/strap

Repository files navigation

STRAP — STRAP Trims, Rejoins And Parses

CI License C

A small, efficient C library providing missing utilities for safe and comfortable string manipulation and time helpers. Designed to be lightweight, portable, and easy to integrate into C projects.

📚 Documentation

🚀 Quick Start

# Clone and build
git clone https://github.com/murapadev/strap.git
cd strap
make

# Install (optional)
sudo make install

# Benchmarks (optional)
make bench
./benchmarks/strap_bench

Windows (MSVC + CMake)

# From a Visual Studio Developer Command Prompt
git clone https://github.com/murapadev/strap.git
cd strap
scripts\build_windows_msvc.bat Release

The helper script configures the Visual Studio generator via CMake, builds the static library, and runs the unit tests. Adjust the generator string or build type inside the script to match your environment.

🔔 What's New in v0.2

  • Faster joins and file reads through tighter allocation strategies
  • New helpers: strstartswith, strendswith, and strreplace
  • Unified error reporting via strap_last_error() and strap_error_string()
  • Scriptable micro-benchmarks with make bench

Basic Usage

#include <stdio.h>
#include "strap.h"

int main(void) {
    // Safe line reading
    char *line = afgets(stdin);
    if (line) {
        char *trimmed = strtrim(line);
        printf("Trimmed: '%s'\n", trimmed);
        free(line);
        free(trimmed);
    }

    // String joining
    const char *parts[] = {"Hello", "world", "from", "STRAP"};
    char *joined = strjoin(parts, 4, " ");
    printf("%s\n", joined);
    free(joined);

    return 0;
}

📚 See the Wiki for complete documentation, examples, and advanced usage.

🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

⚠️ Error Handling

All STRAP APIs set a thread-local error code. On failure, query the cause:

char *trimmed = strtrim(raw_line);
if (!trimmed) {
    fprintf(stderr, "STRAP error: %s\n", strap_error_string(strap_last_error()));
    return EXIT_FAILURE;
}

Call strap_clear_error() when you want to reset the status manually.

🗺️ Roadmap

v0.2 (Current) ✅

  • Performance optimizations
  • Additional string utilities
  • Enhanced error handling
  • Benchmark suite

v0.3 (In Progress)

  • Extended locale-aware helpers
  • Optional arena allocator for transient strings
  • Timezone-aware time helpers

v0.4 (Upcoming)

  • Additional performance optimizations
    • SIMD-accelerated paths for common hot functions (strtrim, strjoin)
    • Streaming-friendly buffering for afgets and file helpers (strap_line_buffer_read)
  • Extended string manipulation utilities
    • High-level split helpers with delimiter limits and predicates (strsplit_limit, strsplit_predicate)
    • Case-insensitive comparison helpers (strap_strcasecmp, strcaseeq)
  • Cross-platform improvements
    • Official Windows/MSVC build scripts and CI coverage
    • Locale/timezone shims for BSD and musl-targeted systems
  • Enhanced documentation
    • Cookbook-style guides for common patterns (log parsing, CSV wrangling)
    • API reference refresh with usage notes and complexity details

📄 License

MIT Licensed - see LICENSE for details.


STRAP - Making C string and time operations safer and more convenient.

About

A small, efficient C library providing missing utilities for safe and comfortable string manipulation and time helpers. Designed to be lightweight, portable, and easy to integrate into C projects.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages