aboutsummaryrefslogtreecommitdiff
path: root/src/string_immutable.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/string_immutable.zig')
-rw-r--r--src/string_immutable.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig
index e3e72726f..db1d459af 100644
--- a/src/string_immutable.zig
+++ b/src/string_immutable.zig
@@ -498,6 +498,15 @@ test "StringOrTinyString Lowercase" {
try std.testing.expectEqualStrings("hello!!!!!", str.slice());
}
+/// Copy a string into a buffer
+/// Return the copied version
+pub fn copy(buf: []u8, src: []const u8) []const u8 {
+ const len = @min(buf.len, src.len);
+ if (len > 0)
+ @memcpy(buf.ptr, src.ptr, len);
+ return buf[0..len];
+}
+
/// startsWith except it checks for non-empty strings
pub fn hasPrefix(self: string, str: string) bool {
return str.len > 0 and startsWith(self, str);