MCPcopy Create free account
hub / github.com/apache/fory / encode_with_encoding

Method encode_with_encoding

rust/fory-core/src/meta/meta_string.rs:277–366  ·  view source on GitHub ↗
(
        &self,
        input: &str,
        encoding: Encoding,
    )

Source from the content-addressed store, hash-verified

275 }
276
277 pub fn encode_with_encoding(
278 &self,
279 input: &str,
280 encoding: Encoding,
281 ) -> Result<MetaString, Error> {
282 if input.is_empty() {
283 return MetaString::new(
284 input.to_string(),
285 Encoding::Utf8,
286 vec![],
287 self.special_char1,
288 self.special_char2,
289 );
290 }
291 ensure!(
292 input.len() < SHORT_MAX_VALUE,
293 Error::encode_error(format!(
294 "Meta string is too long, max:{SHORT_MAX_VALUE}, current:{}",
295 input.len()
296 ))
297 );
298 ensure!(
299 encoding == Encoding::Utf8 || self.is_latin(input),
300 Error::encode_error("Non-ASCII characters in meta string are not allowed")
301 );
302
303 if input.is_empty() {
304 return MetaString::new(
305 input.to_string(),
306 Encoding::Utf8,
307 vec![],
308 self.special_char1,
309 self.special_char2,
310 );
311 };
312
313 match encoding {
314 Encoding::LowerSpecial => {
315 let encoded_data = self.encode_lower_special(input)?;
316 MetaString::new(
317 input.to_string(),
318 encoding,
319 encoded_data,
320 self.special_char1,
321 self.special_char2,
322 )
323 }
324 Encoding::LowerUpperDigitSpecial => {
325 let encoded_data = self.encode_lower_upper_digit_special(input)?;
326 MetaString::new(
327 input.to_string(),
328 encoding,
329 encoded_data,
330 self.special_char1,
331 self.special_char2,
332 )
333 }
334 Encoding::FirstToLowerSpecial => {

Callers 4

encodeMethod · 0.45
encode_with_encodingsMethod · 0.45
test_encode_empty_stringFunction · 0.45

Calls 6

is_emptyMethod · 0.80
to_stringMethod · 0.45
encode_lower_specialMethod · 0.45

Tested by 2

test_encode_empty_stringFunction · 0.36