1/* 2 * Copyright (C) 2006 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// 18// Provide access to a virtual directory in "asset space". Most of the 19// implementation is in the header file or in friend functions in 20// AssetManager. 21// 22#include <androidfw/AssetDir.h> 23 24using namespace android; 25 26 27/* 28 * Find a matching entry in a vector of FileInfo. Because it's sorted, we 29 * can use a binary search. 30 * 31 * Assumes the vector is sorted in ascending order. 32 */ 33/*static*/ int AssetDir::FileInfo::findEntry(const SortedVector<FileInfo>* pVector, 34 const String8& fileName) 35{ 36 FileInfo tmpInfo; 37 38 tmpInfo.setFileName(fileName); 39 return pVector->indexOf(tmpInfo); 40 41#if 0 // don't need this after all (uses 1/2 compares of SortedVector though) 42 int lo, hi, cur; 43 44 lo = 0; 45 hi = pVector->size() -1; 46 while (lo <= hi) { 47 int cmp; 48 49 cur = (hi + lo) / 2; 50 cmp = strcmp(pVector->itemAt(cur).getFileName(), fileName); 51 if (cmp == 0) { 52 /* match, bail */ 53 return cur; 54 } else if (cmp < 0) { 55 /* too low */ 56 lo = cur + 1; 57 } else { 58 /* too high */ 59 hi = cur -1; 60 } 61 } 62 63 return -1; 64#endif 65} 66 67