const std = @import("std");

/// Process escape sequences in a raw string literal.
pub fn unescapeString(allocator: std.mem.Allocator, raw: []const u8) ![]u8 {
    var result = try allocator.alloc(u8, raw.len);
    var i: usize = 0;
    var j: usize = 0;
    while (i < raw.len) {
        if (raw[i] == '\\' and i + 1 < raw.len) {
            i += 1;
            result[j] = switch (raw[i]) {
                'n' => '\n',
                't' => '\t',
                'r' => '\r',
                '\\' => '\\',
                '"' => '"',
                '0' => 0,
                else => raw[i],
            };
        } else {
            result[j] = raw[i];
        }
        j += 1;
        i += 1;
    }
    return result[0..j];
}
