Substring
Source: lib/substring.x
Guide: Iteration
Borrowed immutable views of String bytes.
Include it with #include "substring.x".
Primary API
| Function | Summary |
|---|---|
String.substring | Returns a borrowed immutable view of the requested byte range. |
Substring.compare | Compares contents in bytewise lexical order. |
Substring.equal | Compares contents without materializing either view. |
Substring.hash | Hashes the referenced bytes, independent of their source or offset. |
Substring.len | Returns the byte length without allocating. |
Substring.new | Borrows length bytes at offset. |
Substring.str | Materializes a canonical String in the active pool. |
Substring.string | Materializes the same canonical String as str(). |
Substring.try_next | Yields the next word view. |
String
String.substring
Substring String.substring(String source, int offset, int length)
Returns a borrowed immutable view of the requested byte range.
Source: lib/substring.x
Substring
Substring.compare
inline int Substring.compare(Substring left, Substring right)
Compares contents in bytewise lexical order.
Source: lib/substring.x
Substring.equal
inline int Substring.equal(Substring left, Substring right)
Compares contents without materializing either view.
Source: lib/substring.x
Substring.hash
inline unsigned Substring.hash(Substring view)
Hashes the referenced bytes, independent of their source or offset.
Source: lib/substring.x
Substring.len
inline int Substring.len(Substring view)
Returns the byte length without allocating.
Source: lib/substring.x
Substring.new
Substring Substring.new(String source, int offset, int length)
Borrows length bytes at offset. An invalid range raises bad-arg.
Source: lib/substring.x
Substring.str
String Substring.str(Substring view)
Materializes a canonical String in the active pool. Repeated conversion reuses the canonical value. The result follows its actual owning pool.
Source: lib/substring.x
Substring.string
String Substring.string(Substring view)
Materializes the same canonical String as str().
Source: lib/substring.x
Substring.try_next
int Substring.try_next(String source, int &cursor, Substring &out)
Yields the next word view. Start the caller-owned cursor at zero. The source must stay live; exhaustion leaves cursor and out unchanged. foreach (Substr word in source) uses this allocation-free cursor.
Source: lib/substring.x
Public types
| Type | Kind | Summary |
|---|---|---|
Substr | alias | Short name for the same borrowed view representation as Substring. |
Substring | struct | A borrowed immutable range of a String. |
Substr
typedef Substring Substr
Short name for the same borrowed view representation as Substring.
Source: lib/substring.x
Substring
typedef struct Substring { String source; int offset, length; } Substring
A borrowed immutable range of a String. Assignment copies the view and allocates nothing. Keep the source alive and unchanged through every use; use str() or string() to obtain a canonical String in the active pool. Construct views through Substring.new or String.substring.
Source: lib/substring.x