15c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Copyright 2014 The Chromium Authors. All rights reserved.
25c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Use of this source code is governed by a BSD-style license that can be
35c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// found in the LICENSE file.
45c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
55c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#ifndef NET_BASE_NET_STRING_UTIL_H__
65c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#define NET_BASE_NET_STRING_UTIL_H__
75c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
85c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include <string>
95c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
105c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/strings/string16.h"
115c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// String conversion functions.  By default, they're implemented with ICU, but
135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// when building with USE_ICU_ALTERNATIVES, they use platform functions instead.
145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
155c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liunamespace net {
165c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)extern const char* const kCharsetLatin1;
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
195c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Converts |text| using |charset| to UTF-8, and writes it to |output|.
205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// On failure, returns false and |output| is cleared.
215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liubool ConvertToUtf8(const std::string& text, const char* charset,
225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                   std::string* output);
235c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
245c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Converts |text| using |charset| to UTF-8, normalizes the result, and writes
255c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// it to |output|.  On failure, returns false and |output| is cleared.
265c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liubool ConvertToUtf8AndNormalize(const std::string& text, const char* charset,
275c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                               std::string* output);
285c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
295c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// Converts |text| using |charset| to UTF-16, and writes it to |output|.
305c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// On failure, returns false and |output| is cleared.
315c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liubool ConvertToUTF16(const std::string& text, const char* charset,
325c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu                    base::string16* output);
335c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
34cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Converts |text| using |charset| to UTF-16, and writes it to |output|.
35cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Any characters that can not be converted are replaced with U+FFFD.
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)bool ConvertToUTF16WithSubstitutions(const std::string& text,
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                     const char* charset,
38cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                     base::string16* output);
395c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
405c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu}  // namespace net
415c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
425c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#endif  // NET_BASE_NET_STRING_UTIL_H__
43