1eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Copyright (c) 2006, Google Inc.
2eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// All rights reserved.
3eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis//
4eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Redistribution and use in source and binary forms, with or without
5eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// modification, are permitted provided that the following conditions are
6eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// met:
7eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis//
8eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis//     * Redistributions of source code must retain the above copyright
9eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// notice, this list of conditions and the following disclaimer.
10eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis//     * Redistributions in binary form must reproduce the above
11eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// copyright notice, this list of conditions and the following disclaimer
12eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// in the documentation and/or other materials provided with the
13eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// distribution.
14eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis//     * Neither the name of Google Inc. nor the names of its
15eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// contributors may be used to endorse or promote products derived from
16eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// this software without specific prior written permission.
17eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis//
18eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
30eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// string_conversion.h: Conversion between different UTF-8/16/32 encodings.
31eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
32eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis#ifndef COMMON_STRING_CONVERSION_H__
33eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis#define COMMON_STRING_CONVERSION_H__
34eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
35eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis#include <string>
36eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis#include <vector>
374e518a4357a2d1c379d4a91df6d4e153ee791101ivan.penkov@gmail.com
384e518a4357a2d1c379d4a91df6d4e153ee791101ivan.penkov@gmail.com#include "common/using_std_string.h"
399abfe3d0a5bbefd85c54feda0dac2d030cbb5635mmentovai#include "google_breakpad/common/breakpad_types.h"
40eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
41e5dc60822e5938fea2ae892ccddb906641ba174emmentovainamespace google_breakpad {
42eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
43eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonisusing std::vector;
44eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
45eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Convert |in| to UTF-16 into |out|.  Use platform byte ordering.  If the
46eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// conversion failed, |out| will be zero length.
476162aed3c3fcfc53373c963ac375d39a5dfa5a25ted.mielczarek@gmail.comvoid UTF8ToUTF16(const char *in, vector<uint16_t> *out);
48eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
49eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Convert at least one character (up to a maximum of |in_length|) from |in|
50eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// to UTF-16 into |out|.  Return the number of characters consumed from |in|.
51eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Any unused characters in |out| will be initialized to 0.  No memory will
52eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// be allocated by this routine.
536162aed3c3fcfc53373c963ac375d39a5dfa5a25ted.mielczarek@gmail.comint UTF8ToUTF16Char(const char *in, int in_length, uint16_t out[2]);
54eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
55eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Convert |in| to UTF-16 into |out|.  Use platform byte ordering.  If the
56eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// conversion failed, |out| will be zero length.
576162aed3c3fcfc53373c963ac375d39a5dfa5a25ted.mielczarek@gmail.comvoid UTF32ToUTF16(const wchar_t *in, vector<uint16_t> *out);
58eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
59eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Convert |in| to UTF-16 into |out|.  Any unused characters in |out| will be
60eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// initialized to 0.  No memory will be allocated by this routine.
616162aed3c3fcfc53373c963ac375d39a5dfa5a25ted.mielczarek@gmail.comvoid UTF32ToUTF16Char(wchar_t in, uint16_t out[2]);
62eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
63eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis// Convert |in| to UTF-8.  If |swap| is true, swap bytes before converting.
646162aed3c3fcfc53373c963ac375d39a5dfa5a25ted.mielczarek@gmail.comstring UTF16ToUTF8(const vector<uint16_t> &in, bool swap);
65eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
66e5dc60822e5938fea2ae892ccddb906641ba174emmentovai}  // namespace google_breakpad
67eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis
68eee138c2f3b99f55a72f8f241af92e04ab05f99dwaylonis#endif  // COMMON_STRING_CONVERSION_H__
69