OSDN Git Service

Merge "Add @GuardedBy annotation to PersistentDataBlockService#mIsWritable." into...
[android-x86/frameworks-base.git] / tools / aapt / AaptUtil.h
1 /*
2  * Copyright (C) 2014 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 #ifndef H_AAPT_UTIL
18 #define H_AAPT_UTIL
19
20 #include <utils/KeyedVector.h>
21 #include <utils/SortedVector.h>
22 #include <utils/String8.h>
23 #include <utils/Vector.h>
24
25 namespace AaptUtil {
26
27 android::Vector<android::String8> split(const android::String8& str, const char sep);
28 android::Vector<android::String8> splitAndLowerCase(const android::String8& str, const char sep);
29
30 template <typename KEY, typename VALUE>
31 void appendValue(android::KeyedVector<KEY, android::Vector<VALUE> >& keyedVector,
32         const KEY& key, const VALUE& value);
33
34 template <typename KEY, typename VALUE>
35 void appendValue(android::KeyedVector<KEY, android::SortedVector<VALUE> >& keyedVector,
36         const KEY& key, const VALUE& value);
37
38 //
39 // Implementations
40 //
41
42 template <typename KEY, typename VALUE>
43 void appendValue(android::KeyedVector<KEY, android::Vector<VALUE> >& keyedVector,
44         const KEY& key, const VALUE& value) {
45     ssize_t idx = keyedVector.indexOfKey(key);
46     if (idx < 0) {
47         idx = keyedVector.add(key, android::Vector<VALUE>());
48     }
49     keyedVector.editValueAt(idx).add(value);
50 }
51
52 template <typename KEY, typename VALUE>
53 void appendValue(android::KeyedVector<KEY, android::SortedVector<VALUE> >& keyedVector,
54         const KEY& key, const VALUE& value) {
55     ssize_t idx = keyedVector.indexOfKey(key);
56     if (idx < 0) {
57         idx = keyedVector.add(key, android::SortedVector<VALUE>());
58     }
59     keyedVector.editValueAt(idx).add(value);
60 }
61
62 } // namespace AaptUtil
63
64 #endif // H_AAPT_UTIL