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

Function decode

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

Source from the content-addressed store, hash-verified

22}
23
24fn decode(value: &str, path: bool) -> Result<String, IriError> {
25 let mut decoded = Vec::new();
26 let bytes = value.as_bytes();
27 let mut i = 0;
28 while i < bytes.len() {
29 if bytes[i] == b'%' {
30 let hex = value
31 .get(i + 1..i + 3)
32 .ok_or_else(|| IriError(value.into()))?;
33 decoded.push(u8::from_str_radix(hex, 16).map_err(|_| IriError(value.into()))?);
34 i += 3;
35 } else {
36 decoded.push(bytes[i]);
37 i += 1;
38 }
39 }
40 let decoded = String::from_utf8(decoded).map_err(|_| IriError(value.into()))?;
41 if encode(&decoded, path) != value {
42 return Err(IriError(value.into()));
43 }
44 Ok(decoded)
45}
46
47pub fn mint_project(project: &ProjectId) -> String {
48 project.to_urn()

Callers 3

parse_childFunction · 0.70
parse_todoFunction · 0.70
parse_findingFunction · 0.70

Calls 6

IriErrorClass · 0.85
encodeFunction · 0.70
getMethod · 0.65
as_bytesMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected