mirror of
https://codeberg.org/andyscott/exercism.git
synced 2024-12-22 14:43:10 -05:00
17 lines
443 B
Zig
17 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;
|
||
|
}
|