Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/security/sandbox/chromium/base/strings/string16.cc
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2013 The Chromium Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#include "base/strings/string16.h"
6
7
#if defined(WCHAR_T_IS_UTF16) && !defined(_AIX)
8
9
#error This file should not be used on 2-byte wchar_t systems
10
// If this winds up being needed on 2-byte wchar_t systems, either the
11
// definitions below can be used, or the host system's wide character
12
// functions like wmemcmp can be wrapped.
13
14
#elif defined(WCHAR_T_IS_UTF32)
15
16
#include <ostream>
17
18
#include "base/strings/utf_string_conversions.h"
19
20
namespace base {
21
22
0
int c16memcmp(const char16* s1, const char16* s2, size_t n) {
23
0
  // We cannot call memcmp because that changes the semantics.
24
0
  while (n-- > 0) {
25
0
    if (*s1 != *s2) {
26
0
      // We cannot use (*s1 - *s2) because char16 is unsigned.
27
0
      return ((*s1 < *s2) ? -1 : 1);
28
0
    }
29
0
    ++s1;
30
0
    ++s2;
31
0
  }
32
0
  return 0;
33
0
}
34
35
0
size_t c16len(const char16* s) {
36
0
  const char16 *s_orig = s;
37
0
  while (*s) {
38
0
    ++s;
39
0
  }
40
0
  return s - s_orig;
41
0
}
42
43
0
const char16* c16memchr(const char16* s, char16 c, size_t n) {
44
0
  while (n-- > 0) {
45
0
    if (*s == c) {
46
0
      return s;
47
0
    }
48
0
    ++s;
49
0
  }
50
0
  return 0;
51
0
}
52
53
0
char16* c16memmove(char16* s1, const char16* s2, size_t n) {
54
0
  return static_cast<char16*>(memmove(s1, s2, n * sizeof(char16)));
55
0
}
56
57
0
char16* c16memcpy(char16* s1, const char16* s2, size_t n) {
58
0
  return static_cast<char16*>(memcpy(s1, s2, n * sizeof(char16)));
59
0
}
60
61
0
char16* c16memset(char16* s, char16 c, size_t n) {
62
0
  char16 *s_orig = s;
63
0
  while (n-- > 0) {
64
0
    *s = c;
65
0
    ++s;
66
0
  }
67
0
  return s_orig;
68
0
}
69
70
namespace string16_internals {
71
72
0
std::ostream& operator<<(std::ostream& out, const string16& str) {
73
0
  return out << UTF16ToUTF8(str);
74
0
}
75
76
0
void PrintTo(const string16& str, std::ostream* out) {
77
0
  *out << str;
78
0
}
79
80
}  // namespace string16_internals
81
82
}  // namespace base
83
84
template class std::
85
    basic_string<base::char16, base::string16_internals::string16_char_traits>;
86
87
#endif  // WCHAR_T_IS_UTF32