-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathResourceFilter.cpp
112 lines (99 loc) · 2.59 KB
/
ResourceFilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// Copyright 2011 The Android Open Source Project
//
// Build resource files from raw assets.
//
#include "ResourceFilter.h"
status_t
ResourceFilter::parse(const char* arg)
{
if (arg == NULL) {
return 0;
}
const char* p = arg;
const char* q;
while (true) {
q = strchr(p, ',');
if (q == NULL) {
q = p + strlen(p);
}
String8 part(p, q-p);
if (part == "zz_ZZ") {
mContainsPseudo = true;
}
int axis;
uint32_t value;
if (AaptGroupEntry::parseNamePart(part, &axis, &value)) {
fprintf(stderr, "Invalid configuration: %s\n", arg);
fprintf(stderr, " ");
for (int i=0; i<p-arg; i++) {
fprintf(stderr, " ");
}
for (int i=0; i<q-p; i++) {
fprintf(stderr, "^");
}
fprintf(stderr, "\n");
return 1;
}
ssize_t index = mData.indexOfKey(axis);
if (index < 0) {
mData.add(axis, SortedVector<uint32_t>());
}
SortedVector<uint32_t>& sv = mData.editValueFor(axis);
sv.add(value);
// if it's a locale with a region, also match an unmodified locale of the
// same language
if (axis == AXIS_LANGUAGE) {
if (value & 0xffff0000) {
sv.add(value & 0x0000ffff);
}
}
p = q;
if (!*p) break;
p++;
}
return NO_ERROR;
}
bool
ResourceFilter::isEmpty() const
{
return mData.size() == 0;
}
bool
ResourceFilter::match(int axis, uint32_t value) const
{
if (value == 0) {
// they didn't specify anything so take everything
return true;
}
ssize_t index = mData.indexOfKey(axis);
if (index < 0) {
// we didn't request anything on this axis so take everything
return true;
}
const SortedVector<uint32_t>& sv = mData.valueAt(index);
return sv.indexOf(value) >= 0;
}
bool
ResourceFilter::match(int axis, const ResTable_config& config) const
{
return match(axis, AaptGroupEntry::getConfigValueForAxis(config, axis));
}
bool
ResourceFilter::match(const ResTable_config& config) const
{
for (int i=AXIS_START; i<=AXIS_END; i++) {
if (!match(i, AaptGroupEntry::getConfigValueForAxis(config, i))) {
return false;
}
}
return true;
}
const SortedVector<uint32_t>* ResourceFilter::configsForAxis(int axis) const
{
ssize_t index = mData.indexOfKey(axis);
if (index < 0) {
return NULL;
}
return &mData.valueAt(index);
}