Skip to main content

Crate sql_dialect_fmt_encoding

Crate sql_dialect_fmt_encoding 

Source
Expand description

Encoding boundary for formatter inputs.

The lexer/parser operate on UTF-8 &str, but the CLI sees arbitrary bytes. This crate keeps that boundary explicit: known Unicode encodings are decoded losslessly, while unknown or malformed byte streams remain opaque so tools do not accidentally rewrite data they do not understand.

The entry point is DecodedText::decode, which sniffs a BOM, decodes when it can, and otherwise keeps the original bytes intact. Edit the recovered text with DecodedText::map_text and round-trip back to bytes with DecodedText::encode; the original encoding (and any BOM) is preserved end to end.

use sql_dialect_fmt_encoding::{DecodedText, TextEncoding};
let decoded = DecodedText::decode("select 1\n".as_bytes());
assert_eq!(decoded.encoding(), TextEncoding::Utf8);
let upper = decoded.map_text(|t| t.to_uppercase());
assert_eq!(upper.encode(), b"SELECT 1\n");

Structs§

DecodedText
The result of decoding a byte stream: either recovered text in a known TextEncoding, or the original bytes preserved verbatim because they could not be decoded.

Enums§

OpaqueReason
Why a byte stream was kept opaque instead of being decoded as text.
TextEncoding
A text encoding that DecodedText can recognize and round-trip.