• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /** Declare opaque structures from ICU4C. */
25 struct UConverter;
26 typedef struct UConverter UConverter;
27 
28 struct UCharsetMatch;
29 typedef struct UCharsetMatch UCharsetMatch;
30 
31 namespace android {
32 
33 class CharacterEncodingDetector {
34 
35     public:
36     CharacterEncodingDetector();
37         ~CharacterEncodingDetector();
38 
39         void addTag(const char *name, const char *value);
40         size_t size();
41 
42         void detectAndConvert();
43         status_t getTag(int index, const char **name, const char**value);
44 
45     private:
46         const UCharsetMatch *getPreferred(
47                 const char *input, size_t len,
48                 const UCharsetMatch** ucma, size_t matches,
49                 bool *goodmatch, int *highestmatch);
50 
51         bool isFrequent(const uint16_t *values, uint32_t c);
52 
53         // cached name and value strings, for native encoding support.
54         // TODO: replace these with byte blob arrays that don't require the data to be
55         // singlenullbyte-terminated
56         StringArray     mNames;
57         StringArray     mValues;
58 
59         UConverter*     mUtf8Conv;
60         const char*     mLocaleEnc;
61 };
62 
63 
64 
65 };  // namespace android
66 
67 #endif
68