YSTest: ContentType.cpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

ContentType.cpp
浏览该文件的文档.
1 /*
2 © 2013-2016, 2019 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #include "YSLib/Service/YModules.h"
29 #include YFM_YSLib_Service_ContentType
30
31 namespace YSLib
32 {
33
34 void
35 MIMEBiMapping::operator+=(const pair<ExtensionType, MIMEType>& pr)
36 {
37 ext_map.insert(pr),
38 inv_map.emplace(pr.second, pr.first);
39 }
40 void
41 MIMEBiMapping::operator+=(const pair<MIMEType, ExtensionType>& pr)
42 {
43 ext_map.emplace(pr.second, pr.first),
44 inv_map.insert(pr);
45 }
46
47 void
48 MIMEBiMapping::operator-=(const pair<ExtensionType, MIMEType>& pr)
49 {
50 ext_map.erase(pr.first),
51 inv_map.erase(pr.second);
52 }
53 void
54 MIMEBiMapping::operator-=(const pair<MIMEType, ExtensionType>& pr)
55 {
56 ext_map.erase(pr.second),
57 inv_map.erase(pr.first);
58 }
59
60
61 void
62 AddMIMEItems(MIMEBiMapping& m, const ValueNode& node,
63 MIMEBiMapping::MIMEType&& pth)
64 {
65 if(!node.empty())
66 for(auto& nd : node)
67 try
68 {
69 pth.push_back(nd.GetName());
70 AddMIMEItems(m, nd, std::move(pth));
71 pth.pop_back();
72 }
73 CatchIgnore(bad_any_cast&)
74 else if(const auto p = AccessPtr<string>(node))
75 m += {*p, !pth.empty() && IsPrefixedIndex(pth.back())
76 ? MIMEBiMapping::MIMEType{pth.cbegin(), std::prev(pth.cend())}
77 : pth};
78 }
79
80 } // namespace YSLib;
81
CatchIgnore
#define CatchIgnore(_ex)
指定异常处理器忽略指定异常。
Definition: YBaseMacro.h:133
YSLib::IsPrefixedIndex
YB_ATTR_nodiscard YF_API YB_PURE bool IsPrefixedIndex(string_view, char='$')
判断字符串是否是前缀索引：一个指定字符和非负整数的组合。
Definition: ValueNode.cpp:194
YSLib::AddMIMEItems
YF_API void AddMIMEItems(MIMEBiMapping &, const ValueNode &, MIMEBiMapping::MIMEType &&={})
根据 NPLA1 节点内容增加 MIME 映射。
Definition: ContentType.cpp:62
ystdex::path
一般路径模板。
Definition: path.hpp:268
YSLib::MIMEBiMapping::operator-=
void operator-=(const pair< ExtensionType, MIMEType > &)
Definition: ContentType.cpp:48
ystdex::bad_any_cast
动态泛型转换失败异常。
Definition: any.h:1091
YSLib::MIMEBiMapping::operator+=
void operator+=(const pair< MIMEType, ExtensionType > &)
Definition: ContentType.cpp:35
YModules.h
YSLib 服务模块配置文件。
YSLib::MIMEBiMapping::ext_map
ExtensionMap ext_map
Definition: ContentType.h:53
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:73
YSLib::MIMEBiMapping::inv_map
MIMEMap inv_map
Definition: ContentType.h:54
YSLib::MIMEBiMapping
MIME 和文件扩展名双向映射。
Definition: ContentType.h:45
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
platform::p
return p p
Definition: YCLib/FileSystem.h:209