namespace AIStudio.Tools.DocumentSegments; /// /// A document which is text itself, e.g., a web page, is in an encoding whose new text the format cannot write /// without damaging characters. /// /// /// The format writes new words in the encoding of the source, which is UTF-8 unless a byte order mark announces /// another Unicode encoding. A source in another encoding, e.g., Windows-1252, would be damaged twice: its own /// characters beyond ASCII cannot be read, and the new words would come out in bytes which its readers take for /// other characters. So the format refuses such a document instead of working on it. /// public sealed class UnsupportedTextEncodingException : Exception { /// /// Creates the exception for a document whose bytes are no valid UTF-8. /// /// The document. /// Why the bytes could not be read. public UnsupportedTextEncodingException(string path, Exception innerException) : base($"The document '{path}' is not valid UTF-8.", innerException) { this.DeclaredEncoding = string.Empty; } /// /// Creates the exception for a document which names another encoding than UTF-8 for itself. /// /// The document. /// The encoding the document names, e.g., "iso-8859-1". public UnsupportedTextEncodingException(string path, string declaredEncoding) : base($"The document '{path}' declares the encoding '{declaredEncoding}'.") { this.DeclaredEncoding = declaredEncoding; } /// /// The encoding the document names for itself, e.g., the charset of a web page; empty when its bytes are no valid UTF-8. /// public string DeclaredEncoding { get; } }