Releases: abin-z/string_view
v0.1.0
🎉 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 usingconst char*andsize_t. -
Rich string operations
Includes:find,rfindfind_first_of,find_first_not_ofsubstr,compare,copystarts_with,ends_with,contains
-
Safe access support
Provides bounds-checked access viaat(). -
Stream output support
Compatible withstd::ostreamviaoperator<<. -
Hash support
Includesstd::hashspecialization for use inunordered_mapandunordered_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_viewbehavior but is designed for C++11 - As a non-owning view, users must ensure the underlying data remains valid
- Passing
nullptrwith 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.