没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > mimeparse |
mimeparse
|
0 | 0 | 22 |
贡献者 | 讨论 | 代码提交 |
This module provides basic functions for parsing mime-type names and matching them against a list of media-ranges.
See section 14.1 of RFC 2616 (the HTTP specification) for a complete explanation. More information on the library can be found in the XML.com article Just use Media Types?
Contents
parse_mime_type() Parses a mime-type into its component parts. parse_media_range() Media-ranges are mime-types with wild-cards and a 'q' quality parameter. quality() Determines the quality ('q') of a mime-type when compared against a list of media-ranges. quality_parsed() Just like quality() except the second parameter must be pre-parsed. fitness_and_quality_parsed() Just like quality_parsed() but also returns the fitness score. best_match() Choose the mime-type with the highest fitness score and quality ('q') from a list of candidates.
UsageIn Erlang1> mimeparse:best_match(["application/xbel+xml", "text/xml"], "text/*;q=0.5,*/*; q=0.1").
"text/xml"Note that neither quality_parsed() nor fitness_and_quality_parsed() are exported from the Erlang version.
In JavaScriptRhino 1.7 release 1 2008 03 06
js> load('mimeparse.js');
js> Mimeparse.bestMatch(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*/*; q=0.1');
text/xmlThis example uses the Rhino JavaScript shell but usage should be similar for other JavaScript environments.
print best_match(['application/xbel+xml', 'text/xml'], 'text/*;q=0.5,*/*; q=0.1');
- text/xmlIn PHPinclude_once 'mimeparse.php';
echo Mimeparse::best_match(array('application/xbel+xml', 'text/xml'),
'text/*;q=0.5,*/*; q=0.1');
>"text/xml"In Python>>> import mimeparse
>>> mimeparse.best_match(['application/xbel+xml', 'text/xml'],
'text/*;q=0.5,*/*; q=0.1')
'text/xml'In Rubyrequire "mimeparse"
>true
MIMEParse.best_match(['application/xbel+xml', 'text/xml'],
'text/*;q=0.5,*/*; q=0.1')
==>"text/xml"In JavaList mimeTypesSupported = Arrays.asList(StringUtils.split(
"application/xbel+xml,text/xml", ','));
String bestMatch = MIMEParse.bestMatch(mimeTypesSupported, "text/*;q=0.5,*/*;q=0.1");In Goimport "mimeparse"
bestmatch := mimeparse.BestMatch(["application/xbel+xml", "text/xml"],
"text/*;q=0.5,*/*; q=0.1");