|
|
constexpr const_reference | operator[] (const std::uint64_t index) const noexcept |
| | Index access (no bounds checking).
|
|
constexpr const_pointer | begin () const noexcept |
| | Pointer to the beginning of data.
|
| constexpr const_pointer | end () const noexcept |
| | Pointer to the end of data (data + len).
|
|
constexpr size_type | size () const noexcept |
| | View length in bytes.
|
|
constexpr bool | empty () const noexcept |
| | Whether the view is empty (len == 0).
|
| constexpr bool | operator== (const string_view &rhs) const noexcept |
| | Compare two views for byte-wise equality.
|
| constexpr string_view | sub (std::uint64_t offset, std::uint64_t length=npos) const noexcept |
| | Returns a substring starting at offset, for length bytes.
|
| constexpr int | compare (const string_view &rhs) const noexcept |
| | Lexical comparison (similar to strcmp()).
|
|
constexpr bool | starts_with (const string_view &prefix) const noexcept |
| | Check whether this view starts with the given prefix.
|
|
constexpr bool | ends_with (const string_view &suffix) const noexcept |
| | Check whether this view ends with the given suffix.
|
| constexpr std::uint64_t | find (const char ch) const noexcept |
| | Returns the index of the first occurrence of a character.
|
| constexpr std::uint64_t | hash (jh::meta::c_hash hash_method=jh::meta::c_hash::fnv1a64) const noexcept |
| | Hash the view content using a selectable non-cryptographic algorithm.
|
| constexpr bool | is_digit () const noexcept |
| | Check if all characters are decimal digits (0-9).
|
| constexpr bool | is_number () const noexcept |
| | Check if the string represents a valid decimal number.
|
| constexpr bool | is_alpha () const noexcept |
| | Check if all characters are alphabetic (A-Z, a-z).
|
| constexpr bool | is_alnum () const noexcept |
| | Check if all characters are alphanumeric (letters or digits).
|
| constexpr bool | is_ascii () const noexcept |
| | Check if all characters are 7-bit ASCII.
|
| constexpr bool | is_printable_ascii () const noexcept |
| | Check if all characters are printable 7-bit ASCII.
|
| constexpr bool | is_legal () const noexcept |
| | Check if all characters are valid (printable ASCII or UTF-8).
|
| constexpr bool | is_hex () const noexcept |
| | Check if the string is a valid hexadecimal sequence.
|
| constexpr bool | is_base64 () const noexcept |
| | Check if the string is valid Base64.
|
| constexpr bool | is_base64url () const noexcept |
| | Check if the string is valid Base64URL.
|
| void | copy_to (char *buffer, const std::uint64_t max_len) const noexcept |
| | Copy the view into a C-style null-terminated buffer.
|
| constexpr std::uint64_t | semantic_len () const noexcept |
| | Returns the semantic length of the UTF-8 string.
|
| constexpr | operator std::string_view () const noexcept |
| | Explicit conversion to std::string_view.
|
| constexpr std::string_view | to_std () const noexcept |
| | Named conversion helper to obtain a std::string_view.
|
| constexpr std::strong_ordering | operator<=> (const string_view &rhs) const noexcept |
| | Three-way comparison operator (spaceship operator).
|
Read-only string view with POD layout.
Holds a raw pointer and a length (not null-terminated). Provides slicing, comparison, and constexpr hashing, all while remaining fully POD (const char* + uint64_t).
Key differences from std::string_view:
-
Always POD layout (aggregate struct, no constructors)
-
operator== performs deep comparison (memcmp)
-
hash() is constexpr-safe and usable in consteval contexts
-
No exceptions, no allocator awareness
Initialization semantics:
-
This type is an aggregate; initialization normally requires both a
const char* and an explicit length.
-
If only a
const char* is provided (without len), then len defaults to 0, producing an empty view.
-
A special helper
from_literal() exists for string literals: it deduces the array size at compile time and creates a view of length N-1 (excluding the null terminator).
-
At runtime, you must always provide both pointer and size explicitly โ this class never computes length automatically.
Usage Model:
-
Typically used as a safe view for
immutable_str
-
Can represent string literals or arena-allocated strings
-
Compile-time hashing supports
jh::meta::t_str
| bool jh::pod::string_view::is_number |
( |
| ) |
const |
|
inlinenodiscardconstexprnoexcept |
Check if the string represents a valid decimal number.
- Returns
true if the string is a valid number, otherwise false.
Grammar (simplified BNF):
[ '+' | '-' ] DIGIT+ [ '.' DIGIT+ ] [ ( 'e' | 'E' ) [ '+' | '-' ] DIGIT+ ]
Equivalent regular expression:
^[+-]?[0-9]+(.[0-9]+)?([eE][+-]?[0-9]+)?$
Rules:
-
The first character may be
'+' or '-'.
-
At least one digit must appear before optional '.' or 'e/E'.
-
If '.' appears, at least one digit must follow (either before or after '.').
-
If 'e' or 'E' appears, it must be followed by an optional sign and at least one digit.
-
Only decimal notation is supported (no hex, octal, binary, or locale-specific formats).
do NOT apply [[likely]] as this is constexpr
| std::strong_ordering jh::pod::string_view::operator<=> |
( |
const string_view & | rhs | ) |
const |
|
inlineconstexprnoexcept |
Three-way comparison operator (spaceship operator).
Performs a lexicographical three-way comparison between two string_view instances, returning a value of type std::strong_ordering.
Semantics:
-
Returns
std::strong_ordering::less if *this < rhs
-
Returns
std::strong_ordering::equal if *this == rhs
-
Returns
std::strong_ordering::greater if *this > rhs
The comparison is implemented in terms of compare(), and therefore follows identical lexicographic ordering rules. This ensures bitwise consistency between compare(), operator==, and all derived relational operators.
Properties:
-
Guaranteed constexpr and noexcept.
-
Implements a strict total ordering (same as
std::string_view).
-
Automatically enables all relational operators (
<, <=, >, >=) via the compiler.
- Parameters
-
- Returns
std::strong_ordering value indicating the lexicographic relation.
- See also
- compare()
-
operator==()