blob: 3655a91fe612d1380cbab5684d049eb2b2c07beb [file] [log] [blame]
Marco Nelissen544ad2b2013-11-13 14:18:21 -08001/*
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
28namespace android {
29
30class 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, const UCharsetMatch** ucma, size_t matches);
45
46 bool isFrequent(const uint16_t *values, uint32_t c);
47
48 // cached name and value strings, for native encoding support.
49 // TODO: replace these with byte blob arrays that don't require the data to be
50 // singlenullbyte-terminated
51 StringArray mNames;
52 StringArray mValues;
53
54 UConverter* mUtf8Conv;
55};
56
57
58
59}; // namespace android
60
61#endif