blob: 89e1ee81d80b0653fdf31b461f04df2c59bd5f45 [file] [log] [blame]
Adam Lesinskifab50872014-04-16 14:40:42 -07001/*
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
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080017#ifndef H_AAPT_UTIL
18#define H_AAPT_UTIL
Adam Lesinskifab50872014-04-16 14:40:42 -070019
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080020#include <utils/KeyedVector.h>
21#include <utils/SortedVector.h>
Adam Lesinskifab50872014-04-16 14:40:42 -070022#include <utils/String8.h>
23#include <utils/Vector.h>
24
25namespace AaptUtil {
26
27android::Vector<android::String8> split(const android::String8& str, const char sep);
28android::Vector<android::String8> splitAndLowerCase(const android::String8& str, const char sep);
29
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080030template <typename KEY, typename VALUE>
31void appendValue(android::KeyedVector<KEY, android::Vector<VALUE> >& keyedVector,
32 const KEY& key, const VALUE& value);
33
34template <typename KEY, typename VALUE>
35void appendValue(android::KeyedVector<KEY, android::SortedVector<VALUE> >& keyedVector,
36 const KEY& key, const VALUE& value);
37
38//
39// Implementations
40//
41
42template <typename KEY, typename VALUE>
43void 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
52template <typename KEY, typename VALUE>
53void 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
Adam Lesinskifab50872014-04-16 14:40:42 -070062} // namespace AaptUtil
63
Adam Lesinskic3dc0b52014-11-03 12:05:15 -080064#endif // H_AAPT_UTIL