2026-01-05 14:56:10 +00:00
|
|
|
namespace AIStudio.Tools.MIME;
|
|
|
|
|
|
2026-01-05 15:38:52 +00:00
|
|
|
public class TextBuilder : ISubtype
|
2026-01-05 14:56:10 +00:00
|
|
|
{
|
2026-01-05 16:00:57 +00:00
|
|
|
private const BaseType BASE_TYPE = BaseType.TEXT;
|
|
|
|
|
|
|
|
|
|
private TextBuilder()
|
2026-01-05 14:56:10 +00:00
|
|
|
{
|
|
|
|
|
}
|
2026-01-05 15:38:52 +00:00
|
|
|
|
2026-01-05 16:00:57 +00:00
|
|
|
public static TextBuilder Create() => new();
|
2026-01-05 14:56:10 +00:00
|
|
|
|
|
|
|
|
private TextSubtype subtype;
|
|
|
|
|
|
|
|
|
|
public TextBuilder UseSubtype(string subType)
|
|
|
|
|
{
|
|
|
|
|
this.subtype = subType.ToLowerInvariant() switch
|
|
|
|
|
{
|
|
|
|
|
"plain" => TextSubtype.PLAIN,
|
|
|
|
|
"html" => TextSubtype.HTML,
|
|
|
|
|
"css" => TextSubtype.CSS,
|
|
|
|
|
"csv" => TextSubtype.CSV,
|
|
|
|
|
"javascript" => TextSubtype.JAVASCRIPT,
|
|
|
|
|
"xml" => TextSubtype.XML,
|
|
|
|
|
"markdown" => TextSubtype.MARKDOWN,
|
|
|
|
|
"json" => TextSubtype.JSON,
|
|
|
|
|
|
|
|
|
|
_ => throw new ArgumentException("Unsupported MIME text subtype.", nameof(subType))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextBuilder UseSubtype(TextSubtype subType)
|
|
|
|
|
{
|
|
|
|
|
this.subtype = subType;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region Implementation of IMIMESubtype
|
|
|
|
|
|
|
|
|
|
public MIMEType Build() => new()
|
|
|
|
|
{
|
|
|
|
|
Type = this,
|
2026-01-05 16:00:57 +00:00
|
|
|
TextRepresentation = $"{BASE_TYPE}/{this.subtype}".ToLowerInvariant()
|
2026-01-05 14:56:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|