mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-11-14 07:10:48 -05:00
16 lines
443 B
Zig
16 lines
443 B
Zig
const std = @import("std");
|
|
const mem = std.mem;
|
|
|
|
pub fn rotate(allocator: mem.Allocator, text: []const u8, shiftKey: u5) mem.Allocator.Error![]u8 {
|
|
const result = try allocator.alloc(u8, text.len);
|
|
|
|
for (text, 0..) |c, i| {
|
|
result[i] = switch(c) {
|
|
'a'...'z' => (c - 'a' + shiftKey) % 26 + 'a',
|
|
'A'...'Z' => (c - 'A' + shiftKey) % 26 + 'A',
|
|
else => c,
|
|
};
|
|
}
|
|
|
|
return result;
|
|
}
|