Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsString.h
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
#ifndef nsString_h___
8
#define nsString_h___
9
10
#include "mozilla/Attributes.h"
11
12
#include "nsStringFwd.h"
13
14
#include "nsAString.h"
15
#include "nsDependentSubstring.h"
16
#include "nsReadableUtils.h"
17
18
// enable support for the obsolete string API if not explicitly disabled
19
#ifndef MOZ_STRING_WITH_OBSOLETE_API
20
#define MOZ_STRING_WITH_OBSOLETE_API 1
21
#endif
22
23
#include "nsTString.h"
24
25
static_assert(sizeof(char16_t) == 2, "size of char16_t must be 2");
26
static_assert(sizeof(nsString::char_type) == 2,
27
              "size of nsString::char_type must be 2");
28
static_assert(nsString::char_type(-1) > nsString::char_type(0),
29
              "nsString::char_type must be unsigned");
30
static_assert(sizeof(nsCString::char_type) == 1,
31
              "size of nsCString::char_type must be 1");
32
33
static_assert(sizeof(nsTLiteralString<char>) == sizeof(nsTString<char>),
34
              "nsLiteralCString can masquerade as nsCString, "
35
              "so they must have identical layout");
36
37
static_assert(sizeof(nsTLiteralString<char16_t>) == sizeof(nsTString<char16_t>),
38
              "nsTLiteralString can masquerade as nsString, "
39
              "so they must have identical layout");
40
41
42
/**
43
 * A helper class that converts a UTF-16 string to ASCII in a lossy manner
44
 */
45
class NS_LossyConvertUTF16toASCII : public nsAutoCString
46
{
47
public:
48
  explicit NS_LossyConvertUTF16toASCII(const char16ptr_t aString)
49
0
  {
50
0
    LossyAppendUTF16toASCII(mozilla::MakeStringSpan(aString), *this);
51
0
  }
52
53
  NS_LossyConvertUTF16toASCII(const char16ptr_t aString, uint32_t aLength)
54
0
  {
55
0
    LossyAppendUTF16toASCII(Substring(static_cast<const char16_t*>(aString), aLength), *this);
56
0
  }
57
58
  explicit NS_LossyConvertUTF16toASCII(const nsAString& aString)
59
  {
60
    LossyAppendUTF16toASCII(aString, *this);
61
  }
62
63
private:
64
  // NOT TO BE IMPLEMENTED
65
  NS_LossyConvertUTF16toASCII(char) = delete;
66
};
67
68
69
class NS_ConvertASCIItoUTF16 : public nsAutoString
70
{
71
public:
72
  explicit NS_ConvertASCIItoUTF16(const char* aCString)
73
96
  {
74
96
    AppendASCIItoUTF16(mozilla::MakeStringSpan(aCString), *this);
75
96
  }
76
77
  NS_ConvertASCIItoUTF16(const char* aCString, uint32_t aLength)
78
5.77k
  {
79
5.77k
    AppendASCIItoUTF16(Substring(aCString, aLength), *this);
80
5.77k
  }
81
82
  explicit NS_ConvertASCIItoUTF16(const nsACString& aCString)
83
0
  {
84
0
    AppendASCIItoUTF16(aCString, *this);
85
0
  }
86
87
private:
88
  // NOT TO BE IMPLEMENTED
89
  NS_ConvertASCIItoUTF16(char16_t) = delete;
90
};
91
92
93
/**
94
 * A helper class that converts a UTF-16 string to UTF-8
95
 */
96
class NS_ConvertUTF16toUTF8 : public nsAutoCString
97
{
98
public:
99
  explicit NS_ConvertUTF16toUTF8(const char16ptr_t aString)
100
0
  {
101
0
    AppendUTF16toUTF8(mozilla::MakeStringSpan(aString), *this);
102
0
  }
103
104
  NS_ConvertUTF16toUTF8(const char16ptr_t aString, uint32_t aLength)
105
0
  {
106
0
    AppendUTF16toUTF8(Substring(static_cast<const char16_t*>(aString), aLength), *this);
107
0
  }
108
109
  explicit NS_ConvertUTF16toUTF8(const nsAString& aString)
110
3.04M
  {
111
3.04M
    AppendUTF16toUTF8(aString, *this);
112
3.04M
  }
113
114
private:
115
  // NOT TO BE IMPLEMENTED
116
  NS_ConvertUTF16toUTF8(char) = delete;
117
};
118
119
120
class NS_ConvertUTF8toUTF16 : public nsAutoString
121
{
122
public:
123
  explicit NS_ConvertUTF8toUTF16(const char* aCString)
124
  {
125
    AppendUTF8toUTF16(mozilla::MakeStringSpan(aCString), *this);
126
  }
127
128
  NS_ConvertUTF8toUTF16(const char* aCString, uint32_t aLength)
129
0
  {
130
0
    AppendUTF8toUTF16(Substring(aCString, aLength), *this);
131
0
  }
132
133
  explicit NS_ConvertUTF8toUTF16(const nsACString& aCString)
134
60.0k
  {
135
60.0k
    AppendUTF8toUTF16(aCString, *this);
136
60.0k
  }
137
138
private:
139
  // NOT TO BE IMPLEMENTED
140
  NS_ConvertUTF8toUTF16(char16_t) = delete;
141
};
142
143
// the following are included/declared for backwards compatibility
144
#include "nsDependentString.h"
145
#include "nsLiteralString.h"
146
#include "nsPromiseFlatString.h"
147
148
#endif // !defined(nsString_h___)