Function resolve_inplace [src]

Resolves a URI against a base URI, conforming to RFC 3986, Section 5. Copies new to the beginning of aux_buf.*, allowing the slices to overlap, then parses new as a URI, and then resolves the path in place. If a merge needs to take place, the newly constructed path will be stored in aux_buf.* just after the copied new, and aux_buf.* will be modified to only contain the remaining unused space.

Prototype

pub fn resolve_inplace(base: Uri, new: []const u8, aux_buf: *[]u8) ResolveInPlaceError!Uri

Parameters

base: Urinew: []const u8aux_buf: *[]u8

Possible Errors

InvalidFormat ParseError
InvalidPort ParseError
NoSpaceLeft
UnexpectedCharacter ParseError

Source

pub fn resolve_inplace(base: Uri, new: []const u8, aux_buf: *[]u8) ResolveInPlaceError!Uri { std.mem.copyForwards(u8, aux_buf.*, new); // At this point, new is an invalid pointer. const new_mut = aux_buf.*[0..new.len]; aux_buf.* = aux_buf.*[new.len..]; const new_parsed = parse(new_mut) catch |err| (parseAfterScheme("", new_mut) catch return err); // As you can see above, `new_mut` is not a const pointer. const new_path: []u8 = @constCast(new_parsed.path.percent_encoded); if (new_parsed.scheme.len > 0) return .{ .scheme = new_parsed.scheme, .user = new_parsed.user, .password = new_parsed.password, .host = new_parsed.host, .port = new_parsed.port, .path = remove_dot_segments(new_path), .query = new_parsed.query, .fragment = new_parsed.fragment, }; if (new_parsed.host) |host| return .{ .scheme = base.scheme, .user = new_parsed.user, .password = new_parsed.password, .host = host, .port = new_parsed.port, .path = remove_dot_segments(new_path), .query = new_parsed.query, .fragment = new_parsed.fragment, }; const path, const query = if (new_path.len == 0) .{ base.path, new_parsed.query orelse base.query, } else if (new_path[0] == '/') .{ remove_dot_segments(new_path), new_parsed.query, } else .{ try merge_paths(base.path, new_path, aux_buf), new_parsed.query, }; return .{ .scheme = base.scheme, .user = base.user, .password = base.password, .host = base.host, .port = base.port, .path = path, .query = query, .fragment = new_parsed.fragment, }; }