Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/ipc/glue/StringUtil.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "base/string_util.h"
8
9
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
10
// Use of this source code is governed by a BSD-style license that can be
11
// found in the LICENSE file.
12
13
#include "base/sys_string_conversions.h"
14
15
#include "base/string_piece.h"
16
#include "base/string_util.h"
17
18
#include "build/build_config.h"
19
20
// FIXME/cjones: these really only pertain to the linux sys string
21
// converters.
22
#ifdef WCHAR_T_IS_UTF16
23
#  define ICONV_WCHAR_T_ENCODING "UTF-16"
24
#else
25
#  define ICONV_WCHAR_T_ENCODING "WCHAR_T"
26
#endif
27
28
// FIXME/cjones: BIG assumption here that std::string is a good
29
// container of UTF8-encoded strings.  this is probably wrong, as its
30
// API doesn't really make sense for UTF8.
31
32
namespace base {
33
34
// FIXME/cjones: as its name implies, this function is a hack.
35
template<typename FromType, typename ToType>
36
ToType
37
GhettoStringConvert(const FromType& in)
38
0
{
39
0
  // FIXME/cjones: assumes no non-ASCII characters in |in|
40
0
  ToType out;
41
0
  out.resize(in.length());
42
0
  for (int i = 0; i < static_cast<int>(in.length()); ++i)
43
0
      out[i] = static_cast<typename ToType::value_type>(in[i]);
44
0
  return out;
45
0
}
Unexecuted instantiation: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > base::GhettoStringConvert<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Unexecuted instantiation: std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > base::GhettoStringConvert<StringPiece, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > >(StringPiece const&)
46
47
} // namespace base
48
49
// Implement functions that were in the chromium ICU library, which
50
// we're not taking.
51
52
std::string
53
WideToUTF8(const std::wstring& wide)
54
0
{
55
0
    return base::SysWideToUTF8(wide);
56
0
}
57
58
std::wstring
59
UTF8ToWide(const StringPiece& utf8)
60
0
{
61
0
    return base::SysUTF8ToWide(utf8);
62
0
}
63
64
namespace base {
65
66
// FIXME/cjones: here we're entirely replacing the linux string
67
// converters, and implementing the one that doesn't exist for OS X
68
// and Windows.
69
70
#if !defined(OS_MACOSX) && !defined(OS_WIN)
71
0
std::string SysWideToUTF8(const std::wstring& wide) {
72
0
  // FIXME/cjones: do this with iconv
73
0
  return GhettoStringConvert<std::wstring, std::string>(wide);
74
0
}
75
#endif
76
77
#if !defined(OS_MACOSX) && !defined(OS_WIN)
78
0
std::wstring SysUTF8ToWide(const StringPiece& utf8) {
79
0
  // FIXME/cjones: do this with iconv
80
0
  return GhettoStringConvert<StringPiece, std::wstring>(utf8);
81
0
}
82
83
0
std::string SysWideToNativeMB(const std::wstring& wide) {
84
0
  // TODO(evanm): we can't assume Linux is UTF-8.
85
0
  return SysWideToUTF8(wide);
86
0
}
87
88
0
std::wstring SysNativeMBToWide(const StringPiece& native_mb) {
89
0
  // TODO(evanm): we can't assume Linux is UTF-8.
90
0
  return SysUTF8ToWide(native_mb);
91
0
}
92
#endif
93
94
} // namespace base