Mojo module
string_slice
The StringSlice
type implementation for efficient string operations.
This module provides the StringSlice
type, which is a lightweight view into string data
that enables zero-copy string operations. StringSlice
is designed for high-performance
string manipulation while maintaining memory safety and UTF-8 awareness.
Key Features:
- Zero-copy string views and operations
- UTF-8 aware string slicing and manipulation
- Memory-safe string operations
- Efficient string comparison and search
- Unicode-aware string operations
The StringSlice
type is particularly useful for:
- High-performance string operations without copying
- Efficient string parsing and tokenization
- Memory-safe string manipulation
- Unicode-aware text processing
Example: ```mojo
# Create a string slice
var text = StringSlice("Hello, 世界")
# Zero-copy slicing
var hello = text[0:5] # Hello
# Unicode-aware operations
var world = text[7:13] # "世界"
# String comparison
if text.startswith("Hello"):
print("Found greeting")
```
# Create a string slice
var text = StringSlice("Hello, 世界")
# Zero-copy slicing
var hello = text[0:5] # Hello
# Unicode-aware operations
var world = text[7:13] # "世界"
# String comparison
if text.startswith("Hello"):
print("Found greeting")
```
Aliases
-
StaticString = StringSlice[StaticConstantOrigin]
: An immutable static string slice.
Structs
-
CodepointsIter
: Iterator over theCodepoint
s in a string slice, constructed byStringSlice.codepoints()
. -
CodepointSliceIter
: Iterator forStringSlice
over substring slices containing a single Unicode codepoint. -
StringSlice
: A non-owning view to encoded string data.
Functions
-
get_static_string
: Form a StaticString from compile-time StringSlice values. This guarantees that the returned string is compile-time constant in static memory. It also guarantees that there is a 'nul' zero byte at the end, which is not included in the returned range.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!