1 /*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "Resource.h"
18 #include "StringPiece.h"
19
20 #include <map>
21 #include <string>
22
23 namespace aapt {
24
toString(ResourceType type)25 StringPiece16 toString(ResourceType type) {
26 switch (type) {
27 case ResourceType::kAnim: return u"anim";
28 case ResourceType::kAnimator: return u"animator";
29 case ResourceType::kArray: return u"array";
30 case ResourceType::kAttr: return u"attr";
31 case ResourceType::kAttrPrivate: return u"attr";
32 case ResourceType::kBool: return u"bool";
33 case ResourceType::kColor: return u"color";
34 case ResourceType::kDimen: return u"dimen";
35 case ResourceType::kDrawable: return u"drawable";
36 case ResourceType::kFraction: return u"fraction";
37 case ResourceType::kId: return u"id";
38 case ResourceType::kInteger: return u"integer";
39 case ResourceType::kIntegerArray: return u"integer-array";
40 case ResourceType::kInterpolator: return u"interpolator";
41 case ResourceType::kLayout: return u"layout";
42 case ResourceType::kMenu: return u"menu";
43 case ResourceType::kMipmap: return u"mipmap";
44 case ResourceType::kPlurals: return u"plurals";
45 case ResourceType::kRaw: return u"raw";
46 case ResourceType::kString: return u"string";
47 case ResourceType::kStyle: return u"style";
48 case ResourceType::kStyleable: return u"styleable";
49 case ResourceType::kTransition: return u"transition";
50 case ResourceType::kXml: return u"xml";
51 }
52 return {};
53 }
54
55 static const std::map<StringPiece16, ResourceType> sResourceTypeMap {
56 { u"anim", ResourceType::kAnim },
57 { u"animator", ResourceType::kAnimator },
58 { u"array", ResourceType::kArray },
59 { u"attr", ResourceType::kAttr },
60 { u"^attr-private", ResourceType::kAttrPrivate },
61 { u"bool", ResourceType::kBool },
62 { u"color", ResourceType::kColor },
63 { u"dimen", ResourceType::kDimen },
64 { u"drawable", ResourceType::kDrawable },
65 { u"fraction", ResourceType::kFraction },
66 { u"id", ResourceType::kId },
67 { u"integer", ResourceType::kInteger },
68 { u"integer-array", ResourceType::kIntegerArray },
69 { u"interpolator", ResourceType::kInterpolator },
70 { u"layout", ResourceType::kLayout },
71 { u"menu", ResourceType::kMenu },
72 { u"mipmap", ResourceType::kMipmap },
73 { u"plurals", ResourceType::kPlurals },
74 { u"raw", ResourceType::kRaw },
75 { u"string", ResourceType::kString },
76 { u"style", ResourceType::kStyle },
77 { u"styleable", ResourceType::kStyleable },
78 { u"transition", ResourceType::kTransition },
79 { u"xml", ResourceType::kXml },
80 };
81
parseResourceType(const StringPiece16 & str)82 const ResourceType* parseResourceType(const StringPiece16& str) {
83 auto iter = sResourceTypeMap.find(str);
84 if (iter == std::end(sResourceTypeMap)) {
85 return nullptr;
86 }
87 return &iter->second;
88 }
89
90 } // namespace aapt
91