MCPcopy Create free account
hub / github.com/Ray-D-Song/lexe / decode

Method decode

modules/llrt_util/src/text_decoder.rs:56–71  ·  view source on GitHub ↗
(&self, ctx: Ctx<'js>, bytes: ObjectBytes<'js>)

Source from the content-addressed store, hash-verified

54 }
55
56 pub fn decode(&self, ctx: Ctx<'js>, bytes: ObjectBytes<'js>) -> Result<String> {
57 let bytes = bytes.as_bytes(&ctx)?;
58 let start_pos = if !self.ignore_bom {
59 match bytes.get(..3) {
60 Some([0xFF, 0xFE, ..]) | Some([0xFE, 0xFF, ..]) => 2,
61 Some([0xEF, 0xBB, 0xBF]) => 3,
62 _ => 0,
63 }
64 } else {
65 0
66 };
67
68 self.encoder
69 .encode_to_string(&bytes[start_pos..], !self.fatal)
70 .or_throw_type(&ctx, "")
71 }
72}

Callers 3

decodeFunction · 0.95
from_encodingMethod · 0.45
byte_lengthFunction · 0.45

Calls 4

or_throw_typeMethod · 0.80
encode_to_stringMethod · 0.80
as_bytesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected