diff --git a/src/dict.zig b/src/dict.zig index 54e85ef..18962a7 100644 --- a/src/dict.zig +++ b/src/dict.zig @@ -33,6 +33,27 @@ fn loadDict() []const Wordle.Word { // allocate all words const dictionary = std.heap.smp_allocator.alloc(Wordle.Word, num) catch unreachable; + // iterate over all lines + var lines = std.mem.splitSequence(u8, src, "\n"); + var idx: usize = 0; + while (lines.next()) |line| { + // skip empty line at end + if (line.len == 0) { + continue; + } + + // assert line is correct length + if (line.len != Wordle.WordLen) { + std.debug.panic("length of '{s}' mismatches {d} characters", .{ line, Wordle.WordLen }); + } + + // copy line bytes over + @memcpy(&dictionary[idx], line); + + // increment dictionary entry + idx += 1; + } + // return complete dictionary return dictionary; } @@ -72,7 +93,7 @@ fn expectNotDictionary(word: Wordle.WordLiteral) !void { } test "in dictionary" { - try expectDictionary("alone"); + try expectDictionary("abash"); } test "not in dictionary" {