1 /* 2 * Copyright (C) 2013 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 _CHARACTER_ENCODING_DETECTOR_H 18 #define _CHARACTER_ENCODING_DETECTOR_H 19 20 #include <media/mediascanner.h> 21 22 #include "StringArray.h" 23 24 #include "unicode/ucnv.h" 25 #include "unicode/ucsdet.h" 26 #include "unicode/ustring.h" 27 28 namespace android { 29 30 class CharacterEncodingDetector { 31 32 public: 33 CharacterEncodingDetector(); 34 ~CharacterEncodingDetector(); 35 36 void addTag(const char *name, const char *value); 37 size_t size(); 38 39 void detectAndConvert(); 40 status_t getTag(int index, const char **name, const char**value); 41 42 private: 43 const UCharsetMatch *getPreferred( 44 const char *input, size_t len, 45 const UCharsetMatch** ucma, size_t matches, 46 bool *goodmatch, int *highestmatch); 47 48 bool isFrequent(const uint16_t *values, uint32_t c); 49 50 // cached name and value strings, for native encoding support. 51 // TODO: replace these with byte blob arrays that don't require the data to be 52 // singlenullbyte-terminated 53 StringArray mNames; 54 StringArray mValues; 55 56 UConverter* mUtf8Conv; 57 }; 58 59 60 61 }; // namespace android 62 63 #endif 64