|
|
|
@ -23,8 +23,8 @@ pub const Path = struct { |
|
|
|
|
|
|
|
|
|
/// Represents an `Entity` in a `Path`, either by name or its numeric id. |
|
|
|
|
pub const EntityPart = union(enum) { |
|
|
|
|
name: []const u8, |
|
|
|
|
id: u32, |
|
|
|
|
name: []const u8, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/// Format used to parse and stringify `Path`s. |
|
|
|
@ -265,8 +265,8 @@ pub const Path = struct { |
|
|
|
|
if (first.absolute != second.absolute) return false; |
|
|
|
|
if (first.parts.len != second.parts.len) return false; |
|
|
|
|
for (first.parts, second.parts) |a, b| switch (a) { |
|
|
|
|
.name => |a_name| if (b != .name or !std.mem.eql(u8, a_name, b.name)) return false, |
|
|
|
|
.id => |a_id| if (b != .id or a_id != b.id) return false, |
|
|
|
|
.name => |a_name| if (b != .name or !std.mem.eql(u8, a_name, b.name)) return false, |
|
|
|
|
}; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
@ -282,8 +282,8 @@ pub const Path = struct { |
|
|
|
|
// Parts themselves. |
|
|
|
|
for (self.parts) |part| |
|
|
|
|
result += switch (part) { |
|
|
|
|
.name => |name| name.len, |
|
|
|
|
.id => |id| numDigits(id), |
|
|
|
|
.name => |name| name.len, |
|
|
|
|
}; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -296,15 +296,15 @@ pub const Path = struct { |
|
|
|
|
} |
|
|
|
|
// Write the first part. |
|
|
|
|
switch (self.parts[0]) { |
|
|
|
|
.name => |name| try writer.writeAll(name), |
|
|
|
|
.id => |id| try writer.writeIntNative(u32, id), |
|
|
|
|
.name => |name| try writer.writeAll(name), |
|
|
|
|
} |
|
|
|
|
// Write the remaining parts, each preceeded bu separator. |
|
|
|
|
for (self.parts[1..]) |part| { |
|
|
|
|
try writer.writeAll(opt.sep); |
|
|
|
|
switch (part) { |
|
|
|
|
.name => |name| try writer.writeAll(name), |
|
|
|
|
.id => |id| try writer.writeIntNative(u32, id), |
|
|
|
|
.name => |name| try writer.writeAll(name), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|