icu_encoding_detection.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_I18N_ICU_ENCODING_DETECTION_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_I18N_ICU_ENCODING_DETECTION_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/i18n/base_i18n_export.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Detect encoding of |text| and put the name of encoding (as returned by ICU)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in |encoding|. For ASCII texts |encoding| will be set to an empty string.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true on success.
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_I18N_EXPORT bool DetectEncoding(const std::string& text,
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                     std::string* encoding);
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Detect all possible encodings of |text| and put their names
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (as returned by ICU) in |encodings|. Returns true on success.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Note: this function may return encodings that may fail to decode |text|,
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// the caller is responsible for handling that.
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_I18N_EXPORT bool DetectAllEncodings(const std::string& text,
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                         std::vector<std::string>* encodings);
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace base
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // BASE_I18N_ICU_ENCODING_DETECTION_H_
31