2using System.Collections.Generic;
4using System.Threading.Tasks;
81 else if (ContentType.StartsWith(
"text/"))
103 public Task<object>
DecodeAsync(
string ContentType,
byte[] Data, Encoding Encoding, KeyValuePair<string, string>[] Fields, Uri BaseUri)
116 switch (FileExtension.ToLower())
135 ContentType =
"text/sgml";
139 ContentType =
"text/richtext";
143 ContentType =
string.Empty;
156 switch (ContentType.ToLower())
159 FileExtension =
"txt";
163 FileExtension =
"sgml";
166 case "text/richtext":
167 FileExtension =
"rtx";
171 FileExtension =
string.Empty;
185 if (Object is
string)
194 foreach (
string s
in AcceptedContentTypes)
196 if (s.StartsWith(
"text/"))
217 public Task<KeyValuePair<byte[], string>>
EncodeAsync(
object Object, Encoding Encoding, params
string[] AcceptedContentTypes)
221 if (Encoding is
null)
223 ContentType = PlainTextCodec.DefaultContentType +
"; charset=utf-8";
224 Encoding = Encoding.UTF8;
227 ContentType = PlainTextCodec.DefaultContentType +
"; charset=" + Encoding.WebName;
229 return Task.FromResult(
new KeyValuePair<
byte[],
string>(Encoding.GetBytes(Object.ToString()), ContentType));
Helps with parsing of commong data types.
static string GetString(byte[] Data, Encoding DefaultEncoding)
Gets a string from its binary representation, taking any Byte Order Mark (BOM) into account.
Static class managing encoding and decoding of internet content.
static bool IsAccepted(string ContentType, params string[] AcceptedContentTypes)
Checks if a given content type is acceptable.
Plain text encoder/decoder.
const string DefaultContentType
text/plain
static readonly string[] PlainTextContentTypes
Plain text content types.
Task< object > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
bool Decodes(string ContentType, out Grade Grade)
If the decoder decodes an object with a given content type.
bool TryGetContentType(string FileExtension, out string ContentType)
Tries to get the content type of an item, given its file extension.
string[] ContentTypes
Supported content types.
static readonly string[] PlainTextFileExtensions
Plain text file extensions.
Task< KeyValuePair< byte[], string > > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
bool TryGetFileExtension(string ContentType, out string FileExtension)
Tries to get the file extension of an item, given its Content-Type.
string[] FileExtensions
Supported file extensions.
PlainTextCodec()
Plain text encoder/decoder.
bool Encodes(object Object, out Grade Grade, params string[] AcceptedContentTypes)
If the encoder encodes a given object.
Basic interface for Internet Content decoders. A class implementing this interface and having a defau...
Basic interface for Internet Content encoders. A class implementing this interface and having a defau...