Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/third_party/rust/sfv/src/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 3 kB image not shown  

Quelle  serializer.rs

  Sprache: Rust
 

use std::fmt::Write as _;

use crate::{utils, Date, Decimal, Integer, KeyRef, RefBareItem, StringRef, TokenRef};

pub(cratestruct Serializer;

impl Serializer {
    pub(cratefn serialize_bare_item<'b>(value: impl Into<RefBareItem<'b>>, output: &'color:red'>mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-bare-item

        match value.into() {
            RefBareItem::Boolean(value) => Self::serialize_bool(value, output),
            RefBareItem::String(value) => Self::serialize_string(value, output),
            RefBareItem::ByteSequence(value) => Self::serialize_byte_sequence(value, output),
            RefBareItem::Token(value) => Self::serialize_token(value, output),
            RefBareItem::Integer(value) => Self::serialize_integer(value, output),
            RefBareItem::Decimal(value) => Self::serialize_decimal(value, output),
            RefBareItem::Date(value) => Self::serialize_date(value, output),
            RefBareItem::DisplayString(value) => Self::serialize_display_string(value, output),
        }
    }

    pub(cratefn serialize_parameter<'b>(
        name: &KeyRef,
        value: impl Into<RefBareItem<'b>>,
        output: &mut String,
    ) {
        // https://httpwg.org/specs/rfc9651.html#ser-params
        output.push(';');
        Self::serialize_key(name, output);

        let value = value.into();
        if value != RefBareItem::Boolean(true) {
            output.push('=');
            Self::serialize_bare_item(value, output);
        }
    }

    pub(cratefn serialize_key(input_key: &KeyRef, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-key

        output.push_str(input_key.as_str());
    }

    pub(cratefn serialize_integer(value: Integer, output: &mut String) {
        //https://httpwg.org/specs/rfc9651.html#ser-integer

        write!(output, "{value}").unwrap();
    }

    pub(cratefn serialize_decimal(value: Decimal, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-decimal

        write!(output, "{value}").unwrap();
    }

    pub(cratefn serialize_string(value: &StringRef, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-string

        output.push('"');
        for char in value.as_str().chars() {
            if char == '\\' || char == '"' {
                output.push('\\');
            }
            output.push(char);
        }
        output.push('"');
    }

    pub(cratefn serialize_token(value: &TokenRef, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-token

        output.push_str(value.as_str());
    }

    pub(cratefn serialize_byte_sequence(value: &[u8], output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-binary

        output.push(':');
        base64::Engine::encode_string(&utils::BASE64, value, output);
        output.push(':');
    }

    pub(cratefn serialize_bool(value: bool, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-boolean

        output.push_str(if value { "?1" } else { "?0" });
    }

    pub(cratefn serialize_date(value: Date, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-date

        write!(output, "{value}").unwrap();
    }

    pub(cratefn serialize_display_string(value: &str, output: &mut String) {
        // https://httpwg.org/specs/rfc9651.html#ser-display

        output.push_str(r#"%""#);
        for c in value.bytes() {
            match c {
                b'%' | b'"' | 0x00..=0x1f | 0x7f..=0xff => {
                    output.push('%');
                    output.push(char::from_digit((u32::from(c) >> 4) & 0xf, 16).unwrap());
                    output.push(char::from_digit(u32::from(c) & 0xf, 16).unwrap());
                }
                _ => output.push(c as char),
            }
        }
        output.push('"');
    }
}

Messung V0.5 in Prozent
C=83 H=93 G=87

¤ Dauer der Verarbeitung: 0.2 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.