Skip to content

Commit 70a009a

Browse files
committed
add eqlDocument comparison
1 parent 8ab9364 commit 70a009a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/url.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,18 @@ pub const URL = struct {
217217
buf.appendSliceAssumeCapacity(query_string);
218218
return buf.items;
219219
}
220+
221+
// Compares two URLs, returning true if it is the same document.
222+
pub fn eqlDocument(self: *const URL, other: *const URL, arena: Allocator) !bool {
223+
if (!std.mem.eql(u8, self.scheme(), other.scheme())) return false;
224+
if (!std.mem.eql(u8, self.host(), other.host())) return false;
225+
if (self.port() != other.port()) return false;
226+
227+
const path1 = try self.uri.path.toRawMaybeAlloc(arena);
228+
const path2 = try other.uri.path.toRawMaybeAlloc(arena);
229+
230+
return std.mem.eql(u8, path1, path2);
231+
}
220232
};
221233

222234
const StitchOpts = struct {

0 commit comments

Comments
 (0)