remove_dot_segments
In-place implementation of RFC 3986, Section 5.2.4.
Function parameters
Parameters
- path:[]u8
Type definitions in this namespace
Types
Returned value may point into `buffer` or be the original string.
Functions
- getHost
- Returned value may point into `buffer` or be the original string.
- getHostAlloc
- Returned value may point into `buffer` or be the original string.
- percentDecodeBackwards
- Percent decodes all %XX where XX is a valid hex number.
- percentDecodeInPlace
- Percent decodes all %XX where XX is a valid hex number.
- parseAfterScheme
- Parses the URI or returns an error.
- parse
- The return value will contain strings pointing into the original `text`.
- resolveInPlace
- Resolves a URI against a base URI, conforming to
Error sets in this namespace
Error Sets
= 255
Values
- host_name_max
- = 255
Source
Implementation
fn remove_dot_segments(path: []u8) Component {
var in_i: usize = 0;
var out_i: usize = 0;
while (in_i < path.len) {
if (std.mem.startsWith(u8, path[in_i..], "./")) {
in_i += 2;
} else if (std.mem.startsWith(u8, path[in_i..], "../")) {
in_i += 3;
} else if (std.mem.startsWith(u8, path[in_i..], "/./")) {
in_i += 2;
} else if (std.mem.eql(u8, path[in_i..], "/.")) {
in_i += 1;
path[in_i] = '/';
} else if (std.mem.startsWith(u8, path[in_i..], "/../")) {
in_i += 3;
while (out_i > 0) {
out_i -= 1;
if (path[out_i] == '/') break;
}
} else if (std.mem.eql(u8, path[in_i..], "/..")) {
in_i += 2;
path[in_i] = '/';
while (out_i > 0) {
out_i -= 1;
if (path[out_i] == '/') break;
}
} else if (std.mem.eql(u8, path[in_i..], ".")) {
in_i += 1;
} else if (std.mem.eql(u8, path[in_i..], "..")) {
in_i += 2;
} else {
while (true) {
path[out_i] = path[in_i];
out_i += 1;
in_i += 1;
if (in_i >= path.len or path[in_i] == '/') break;
}
}
}
return .{ .percent_encoded = path[0..out_i] };
}