Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();

const lib = b.addStaticLibrary("ctregex", "ctregex.zig");
lib.setBuildMode(mode);
lib.install();
const optimize = b.standardOptimizeOption(.{});

const main_tests = b.addTest("tests.zig");
main_tests.setBuildMode(mode);
const lib = b.addStaticLibrary(.{
.name = "ctregex",
.root_source_file = .{ .path = "ctregex.zig" },
.target = target,
.optimize = optimize,
});

const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
b.installArtifact(lib);
}
6 changes: 3 additions & 3 deletions ctregex.zig
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ const RegexParser = struct {
fn ctStr(comptime self: Brackets) []const u8 {
var str: []const u8 = "[";
if (self.is_exclusive) str = str ++ "<not> ";
for (self.rules) |rule, idx| {
for (self.rules, 0..) |rule, idx| {
if (idx > 0) str = str ++ " ";
str = str ++ switch (rule) {
.char => |c| ctUtf8EncodeChar(c),
Expand Down Expand Up @@ -885,7 +885,7 @@ pub fn MatchResult(comptime regex: []const u8, comptime options: MatchOptions) t
if (RegexParser.parse(regex)) |parsed| {
const capture_len = parsed.captures.len;
var capture_names: [capture_len]?[]const u8 = undefined;
for (parsed.captures) |capt, idx| {
for (parsed.captures, 0..) |capt, idx| {
if (capt.capture_info) |info| {
capture_names[idx] = info.name;
}
Expand All @@ -906,7 +906,7 @@ pub fn MatchResult(comptime regex: []const u8, comptime options: MatchOptions) t
pub usingnamespace if (capture_len != 0)
struct {
pub fn capture(self: Self, comptime name: []const u8) ?[]const CharT {
inline for (capture_names2) |maybe_name, curr_idx| {
inline for (capture_names2, 0..) |maybe_name, curr_idx| {
if (maybe_name) |curr_name| {
if (comptime std.mem.eql(u8, name, curr_name))
return self.captures[curr_idx];
Expand Down