MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / encode

Function encode

atomic-core/src/kg/iri.rs:11–22  ·  view source on GitHub ↗
(value: &str, path: bool)

Source from the content-addressed store, hash-verified

9pub struct IriError(pub String);
10
11fn encode(value: &str, path: bool) -> String {
12 let mut encoded = String::new();
13 for byte in value.bytes() {
14 if byte.is_ascii_alphanumeric() || b"-._~".contains(&byte) || (path && byte == b'/') {
15 encoded.push(byte as char);
16 } else {
17 use std::fmt::Write;
18 write!(encoded, "%{byte:02X}").expect("write to string");
19 }
20 }
21 encoded
22}
23
24fn decode(value: &str, path: bool) -> Result<String, IriError> {
25 let mut decoded = Vec::new();

Callers 1

decodeFunction · 0.70

Calls 3

bytesMethod · 0.45
containsMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected