Skip to content

Commit

Permalink
Make all nstring slicing operations inout
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Dec 10, 2024
1 parent 0b2e969 commit 38544a0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions source/numem/string.d
Original file line number Diff line number Diff line change
Expand Up @@ -387,32 +387,32 @@ public:
D slices are short lived and may end up pointing to invalid memory if their string is modified.
*/
@trusted
const(T)[] opSlice(size_t start, size_t end) {
return cast(const(T)[])this.vec_[start..end];
inout(T)[] opSlice(size_t start, size_t end) inout {
return cast(inout(T)[])this.vec_[start..end];
}

/**
Allows slicing the string to the full vector
*/
@trusted
const(T)[] opIndex() {
return cast(const(T)[])this.vec_[0..this.size()];
inout(T)[] opIndex() inout {
return cast(inout(T)[])this.vec_[0..this.size()];
}

/**
Allows slicing the string to get a substring.
*/
@trusted
const(T)[] opIndex(size_t[2] slice) {
return cast(const(T)[])this.vec_[slice[0]..slice[1]];
inout(T)[] opIndex(size_t[2] slice) inout {
return cast(inout(T)[])this.vec_[slice[0]..slice[1]];
}

/**
Allows getting a character from the string.
*/
@trusted
ref const(T) opIndex(size_t index) {
return cast(const(T))(this.vec_.data()[index]);
ref inout(T) opIndex(size_t index) inout {
return cast(inout(T))(this.vec_.data()[index]);
}

/**
Expand All @@ -425,7 +425,7 @@ public:
else
size_t len = other.length;

return this.length == len && this.vec_[0..len] == other[0..len];
return this.length == len && this[0..len] == other[0..len];
}

/**
Expand Down

0 comments on commit 38544a0

Please sign in to comment.