Spicy
Public Member Functions | Static Public Member Functions | Friends | List of all members
spicy::rt::MIMEType Class Reference

#include <mime.h>

Public Member Functions

 MIMEType (std::string_view main, std::string_view sub)
 
 MIMEType (const std::string &type)
 
std::string mainType () const
 
std::string subType () const
 
bool isWildcard () const
 
 MIMEType (const MIMEType &)=default
 
 MIMEType (MIMEType &&) noexcept=default
 
MIMETypeoperator= (const MIMEType &)=default
 
MIMETypeoperator= (MIMEType &&) noexcept=default
 
 operator std::string () const
 
std::string asKey () const
 

Static Public Member Functions

static hilti::rt::Result< MIMETypeparse (const std::string &s)
 

Friends

bool operator== (const MIMEType &a, const MIMEType &b)
 
bool operator!= (const MIMEType &a, const MIMEType &b)
 

Detailed Description

Type representing a MIME type consisting of main type and a subtype.

Constructor & Destructor Documentation

◆ MIMEType() [1/2]

spicy::rt::MIMEType::MIMEType ( std::string_view  main,
std::string_view  sub 
)
inline

Initializes a MIME type from provided main and sub type.

Parameters
mainmain type, with '*' meaning a catch-all wildcard.
submain type, with '*' meaning a catch-all wildcard.

◆ MIMEType() [2/2]

spicy::rt::MIMEType::MIMEType ( const std::string &  type)
inline

Initializes a MIME type from provided string of the form main/sub.

Parameters
mtstring main/sub
Exceptions
<tt>InvalidMIMEType</tt>if it cannot parse the type

Member Function Documentation

◆ asKey()

std::string spicy::rt::MIMEType::asKey ( ) const
inline

Converts the type into textual key suitable for using as an index in map.

Returns
If the main type is a wildcard, returns an empty string. If the sub type is a wildcard, returns just the main type. Otherwise returns the standard main/sub form.

◆ isWildcard()

bool spicy::rt::MIMEType::isWildcard ( ) const
inline

Returns true if either type or subtype is a wildcard.

◆ mainType()

std::string spicy::rt::MIMEType::mainType ( ) const
inline

Returns the main type, with '*' reflecting a wildcard.

◆ parse()

static hilti::rt::Result<MIMEType> spicy::rt::MIMEType::parse ( const std::string &  s)
inlinestatic

Parses a string a/b into a MIME type.

Parameters
stringof the form main/sub.
Returns
parsed type, or an error if not parseable

◆ subType()

std::string spicy::rt::MIMEType::subType ( ) const
inline

Returns the sub type, with '*' reflecting a wildcard.


The documentation for this class was generated from the following file: