Skip to content

Releases: abin-z/string_view

v0.1.0

19 Apr 05:55

Choose a tag to compare

🎉 abin::string_view v0.1.0

Initial release of a lightweight, non-owning string view implementation for C++11 and above.


✨ Overview

abin::string_view is a simple, efficient alternative to std::string_view, designed for environments where C++17 is not available. It provides a familiar interface while remaining lightweight, header-only, and easy to integrate.


🚀 Features

  • Non-owning design
    Holds only a pointer and length without managing memory.

  • Zero-copy access
    Operates directly on existing string data with no additional allocations.

  • Lightweight & efficient
    Minimal internal representation using const char* and size_t.

  • Rich string operations
    Includes:

    • find, rfind
    • find_first_of, find_first_not_of
    • substr, compare, copy
    • starts_with, ends_with, contains
  • Safe access support
    Provides bounds-checked access via at().

  • Stream output support
    Compatible with std::ostream via operator<<.

  • Hash support
    Includes std::hash specialization for use in unordered_map and unordered_set.

  • Header-only & C++11 compatible
    No external dependencies, easy to integrate into existing projects.


🧪 Testing

  • Fully tested using Catch2
  • Verified for correctness across edge cases
  • Memory-safe (no ownership, no leaks)

⚠️ Notes

  • This implementation mimics std::string_view behavior but is designed for C++11
  • As a non-owning view, users must ensure the underlying data remains valid
  • Passing nullptr with non-zero length is undefined behavior

📦 Usage

#include "string_view.h"

abin::string_view sv = "hello world";

if (sv.starts_with("hello")) {
    std::cout << sv.substr(6) << std::endl; // world
}

📌 Future Improvements

  • Further API alignment with C++17 std::string_view
  • Additional performance optimizations
  • Extended test coverage (fuzz / stress tests)

🙌 Acknowledgements

Inspired by std::string_view from the C++17 standard library.