MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / make_external_component

Function make_external_component

crates/cpp/src/symbol_name.rs:12–34  ·  view source on GitHub ↗

encode symbol as alphanumeric by hex-encoding special characters

(input: &str)

Source from the content-addressed store, hash-verified

10
11/// encode symbol as alphanumeric by hex-encoding special characters
12pub fn make_external_component(input: &str) -> String {
13 input
14 .chars()
15 .map(|c| match c {
16 'A'..='Z' | 'a'..='z' | '0'..='9' | '_' => {
17 let mut s = String::new();
18 s.push(c);
19 s
20 }
21 '-' => {
22 let mut s = String::new();
23 s.push('_');
24 s
25 }
26 _ => {
27 let mut s = String::from("X");
28 s.push(hexdigit((c as u32 & 0xf0) >> 4));
29 s.push(hexdigit(c as u32 & 0xf));
30 s
31 }
32 })
33 .collect()
34}
35
36/// encode symbol as alphanumeric by hex-encoding special characters
37pub fn make_external_symbol(module_name: &str, name: &str, variant: abi::AbiVariant) -> String {

Callers 3

generate_functionMethod · 0.85
make_external_symbolFunction · 0.85

Calls 5

newFunction · 0.85
hexdigitFunction · 0.85
collectMethod · 0.80
mapMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected