/work/obj-fuzz/dist/include/nsTStringRepr.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 nsTStringRepr_h |
8 | | #define nsTStringRepr_h |
9 | | |
10 | | #include <type_traits> // std::enable_if |
11 | | |
12 | | #include "mozilla/Char16.h" |
13 | | #include "mozilla/fallible.h" |
14 | | #include "nsStringFlags.h" |
15 | | #include "nsCharTraits.h" |
16 | | |
17 | | template <typename T> class nsTSubstringTuple; |
18 | | |
19 | | // The base for string comparators |
20 | | template <typename T> class nsTStringComparator |
21 | | { |
22 | | public: |
23 | | typedef T char_type; |
24 | | |
25 | 10.5k | nsTStringComparator() {} |
26 | | |
27 | | virtual int operator()(const char_type*, const char_type*, |
28 | | uint32_t, uint32_t) const = 0; |
29 | | }; |
30 | | |
31 | | // The default string comparator (case-sensitive comparision) |
32 | | template <typename T> class nsTDefaultStringComparator |
33 | | : public nsTStringComparator<T> |
34 | | { |
35 | | public: |
36 | | typedef T char_type; |
37 | | |
38 | 10.5k | nsTDefaultStringComparator() {} |
39 | | |
40 | | virtual int operator()(const char_type*, const char_type*, |
41 | | uint32_t, uint32_t) const override; |
42 | | }; |
43 | | |
44 | | extern template class nsTDefaultStringComparator<char>; |
45 | | extern template class nsTDefaultStringComparator<char16_t>; |
46 | | |
47 | | namespace mozilla { |
48 | | |
49 | | // This is mainly intended to be used in the context of nsTStrings where |
50 | | // we want to enable a specific function only for a given character class. In |
51 | | // order for this technique to work the member function needs to be templated |
52 | | // on something other than `T`. We keep this in the `mozilla` namespace rather |
53 | | // than `nsTStringRepr` as it's intentionally not dependent on `T`. |
54 | | // |
55 | | // The 'T' at the end of `Char[16]OnlyT` is refering to the `::type` portion |
56 | | // which will only be defined if the character class is correct. This is similar |
57 | | // to `std::enable_if_t` which is available in C++14, but not C++11. |
58 | | // |
59 | | // `CharType` is generally going to be a shadowed type of `T`. |
60 | | // |
61 | | // Example usage of a function that will only be defined if `T` == `char`: |
62 | | // |
63 | | // template <typename T> |
64 | | // class nsTSubstring : public nsTStringRepr<T> { |
65 | | // template <typename Q = T, typename EnableForChar = typename CharOnlyT<Q>> |
66 | | // int Foo() { return 42; } |
67 | | // }; |
68 | | // |
69 | | // Please note that we had to use a separate type `Q` for this to work. You |
70 | | // will get a semi-decent compiler error if you use `T` directly. |
71 | | |
72 | | template <typename CharType> using CharOnlyT = |
73 | | typename std::enable_if<std::is_same<char, CharType>::value>::type; |
74 | | |
75 | | template <typename CharType> using Char16OnlyT = |
76 | | typename std::enable_if<std::is_same<char16_t, CharType>::value>::type; |
77 | | |
78 | | namespace detail { |
79 | | |
80 | | // nsTStringRepr defines a string's memory layout and some accessor methods. |
81 | | // This class exists so that nsTLiteralString can avoid inheriting |
82 | | // nsTSubstring's destructor. All methods on this class must be const because |
83 | | // literal strings are not writable. |
84 | | // |
85 | | // This class is an implementation detail and should not be instantiated |
86 | | // directly, nor used in any way outside of the string code itself. It is |
87 | | // buried in a namespace to discourage its use in function parameters. |
88 | | // If you need to take a parameter, use [const] ns[C]Substring&. |
89 | | // If you need to instantiate a string, use ns[C]String or descendents. |
90 | | // |
91 | | // NAMES: |
92 | | // nsStringRepr for wide characters |
93 | | // nsCStringRepr for narrow characters |
94 | | template <typename T> class nsTStringRepr |
95 | | { |
96 | | public: |
97 | | typedef mozilla::fallible_t fallible_t; |
98 | | |
99 | | typedef T char_type; |
100 | | |
101 | | typedef nsCharTraits<char_type> char_traits; |
102 | | typedef typename char_traits::incompatible_char_type incompatible_char_type; |
103 | | |
104 | | typedef nsTStringRepr<T> self_type; |
105 | | typedef self_type base_string_type; |
106 | | |
107 | | typedef nsTSubstring<T> substring_type; |
108 | | typedef nsTSubstringTuple<T> substring_tuple_type; |
109 | | |
110 | | typedef nsReadingIterator<char_type> const_iterator; |
111 | | typedef char_type* iterator; |
112 | | |
113 | | typedef nsTStringComparator<char_type> comparator_type; |
114 | | |
115 | | typedef const char_type* const_char_iterator; |
116 | | |
117 | | typedef uint32_t index_type; |
118 | | typedef uint32_t size_type; |
119 | | |
120 | | // These are only for internal use within the string classes: |
121 | | typedef StringDataFlags DataFlags; |
122 | | typedef StringClassFlags ClassFlags; |
123 | | |
124 | | // Reading iterators. |
125 | | const_char_iterator BeginReading() const |
126 | 31.7M | { |
127 | 31.7M | return mData; |
128 | 31.7M | } mozilla::detail::nsTStringRepr<char>::BeginReading() const Line | Count | Source | 126 | 27.9M | { | 127 | 27.9M | return mData; | 128 | 27.9M | } |
mozilla::detail::nsTStringRepr<char16_t>::BeginReading() const Line | Count | Source | 126 | 3.81M | { | 127 | 3.81M | return mData; | 128 | 3.81M | } |
|
129 | | const_char_iterator EndReading() const |
130 | | { |
131 | | return mData + mLength; |
132 | | } |
133 | | |
134 | | // Deprecated reading iterators. |
135 | | const_iterator& BeginReading(const_iterator& aIter) const |
136 | 9.98M | { |
137 | 9.98M | aIter.mStart = mData; |
138 | 9.98M | aIter.mEnd = mData + mLength; |
139 | 9.98M | aIter.mPosition = aIter.mStart; |
140 | 9.98M | return aIter; |
141 | 9.98M | } |
142 | | |
143 | | const_iterator& EndReading(const_iterator& aIter) const |
144 | 9.98M | { |
145 | 9.98M | aIter.mStart = mData; |
146 | 9.98M | aIter.mEnd = mData + mLength; |
147 | 9.98M | aIter.mPosition = aIter.mEnd; |
148 | 9.98M | return aIter; |
149 | 9.98M | } |
150 | | |
151 | | const_char_iterator& BeginReading(const_char_iterator& aIter) const |
152 | | { |
153 | | return aIter = mData; |
154 | | } |
155 | | |
156 | | const_char_iterator& EndReading(const_char_iterator& aIter) const |
157 | | { |
158 | | return aIter = mData + mLength; |
159 | | } |
160 | | |
161 | | // Accessors. |
162 | | template <typename U, typename Dummy> struct raw_type { typedef const U* type; }; |
163 | | #if defined(MOZ_USE_CHAR16_WRAPPER) |
164 | | template <typename Dummy> struct raw_type<char16_t, Dummy> { typedef char16ptr_t type; }; |
165 | | #endif |
166 | | |
167 | | // Returns pointer to string data (not necessarily null-terminated) |
168 | | const typename raw_type<T, int>::type Data() const |
169 | | { |
170 | | return mData; |
171 | | } |
172 | | |
173 | | size_type Length() const |
174 | 102M | { |
175 | 102M | return mLength; |
176 | 102M | } mozilla::detail::nsTStringRepr<char>::Length() const Line | Count | Source | 174 | 96.3M | { | 175 | 96.3M | return mLength; | 176 | 96.3M | } |
mozilla::detail::nsTStringRepr<char16_t>::Length() const Line | Count | Source | 174 | 6.34M | { | 175 | 6.34M | return mLength; | 176 | 6.34M | } |
|
177 | | |
178 | | DataFlags GetDataFlags() const |
179 | | { |
180 | | return mDataFlags; |
181 | | } |
182 | | |
183 | | bool IsEmpty() const |
184 | 12.0M | { |
185 | 12.0M | return mLength == 0; |
186 | 12.0M | } |
187 | | |
188 | | bool IsLiteral() const |
189 | | { |
190 | | return !!(mDataFlags & DataFlags::LITERAL); |
191 | | } |
192 | | |
193 | | bool IsVoid() const |
194 | 3.24M | { |
195 | 3.24M | return !!(mDataFlags & DataFlags::VOIDED); |
196 | 3.24M | } Unexecuted instantiation: mozilla::detail::nsTStringRepr<char16_t>::IsVoid() const mozilla::detail::nsTStringRepr<char>::IsVoid() const Line | Count | Source | 194 | 3.24M | { | 195 | 3.24M | return !!(mDataFlags & DataFlags::VOIDED); | 196 | 3.24M | } |
|
197 | | |
198 | | bool IsTerminated() const |
199 | | { |
200 | | return !!(mDataFlags & DataFlags::TERMINATED); |
201 | | } |
202 | | |
203 | | char_type CharAt(index_type aIndex) const |
204 | | { |
205 | | NS_ASSERTION(aIndex < mLength, "index exceeds allowable range"); |
206 | | return mData[aIndex]; |
207 | | } |
208 | | |
209 | | char_type operator[](index_type aIndex) const |
210 | | { |
211 | | return CharAt(aIndex); |
212 | | } |
213 | | |
214 | | char_type First() const; |
215 | | |
216 | | char_type Last() const; |
217 | | |
218 | | size_type NS_FASTCALL CountChar(char_type) const; |
219 | | int32_t NS_FASTCALL FindChar(char_type, index_type aOffset = 0) const; |
220 | | |
221 | | inline bool Contains(char_type aChar) const |
222 | | { |
223 | | return FindChar(aChar) != kNotFound; |
224 | | } |
225 | | |
226 | | // Equality. |
227 | | bool NS_FASTCALL Equals(const self_type&) const; |
228 | | bool NS_FASTCALL Equals(const self_type&, const comparator_type&) const; |
229 | | |
230 | | bool NS_FASTCALL Equals(const substring_tuple_type& aTuple) const; |
231 | | bool NS_FASTCALL Equals(const substring_tuple_type& aTuple, |
232 | | const comparator_type& aComp) const; |
233 | | |
234 | | bool NS_FASTCALL Equals(const char_type* aData) const; |
235 | | bool NS_FASTCALL Equals(const char_type* aData, |
236 | | const comparator_type& aComp) const; |
237 | | |
238 | | #if defined(MOZ_USE_CHAR16_WRAPPER) |
239 | | template <typename Q = T, typename EnableIfChar16 = Char16OnlyT<Q>> |
240 | | bool NS_FASTCALL Equals(char16ptr_t aData) const |
241 | | { |
242 | | return Equals(static_cast<const char16_t*>(aData)); |
243 | | } |
244 | | template <typename Q = T, typename EnableIfChar16 = Char16OnlyT<Q>> |
245 | | bool NS_FASTCALL Equals(char16ptr_t aData, const comparator_type& aComp) const |
246 | | { |
247 | | return Equals(static_cast<const char16_t*>(aData), aComp); |
248 | | } |
249 | | #endif |
250 | | |
251 | | // An efficient comparison with ASCII that can be used even |
252 | | // for wide strings. Call this version when you know the |
253 | | // length of 'data'. |
254 | | bool NS_FASTCALL EqualsASCII(const char* aData, size_type aLen) const; |
255 | | // An efficient comparison with ASCII that can be used even |
256 | | // for wide strings. Call this version when 'data' is |
257 | | // null-terminated. |
258 | | bool NS_FASTCALL EqualsASCII(const char* aData) const; |
259 | | |
260 | | // EqualsLiteral must ONLY be applied to an actual literal string, or |
261 | | // a char array *constant* declared without an explicit size. |
262 | | // Do not attempt to use it with a regular char* pointer, or with a |
263 | | // non-constant char array variable. Use EqualsASCII for them. |
264 | | // The template trick to acquire the array length at compile time without |
265 | | // using a macro is due to Corey Kosak, with much thanks. |
266 | | template<int N> |
267 | | inline bool EqualsLiteral(const char (&aStr)[N]) const |
268 | 13.0k | { |
269 | 13.0k | return EqualsASCII(aStr, N - 1); |
270 | 13.0k | } Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<17>(char const (&) [17]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<18>(char const (&) [18]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<15>(char const (&) [15]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<10>(char const (&) [10]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<5>(char const (&) [5]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<9>(char const (&) [9]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<8>(char const (&) [8]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<6>(char const (&) [6]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<12>(char const (&) [12]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<11>(char const (&) [11]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<14>(char const (&) [14]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<13>(char const (&) [13]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<19>(char const (&) [19]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<7>(char const (&) [7]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<27>(char const (&) [27]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<25>(char const (&) [25]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<24>(char const (&) [24]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<32>(char const (&) [32]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<5>(char const (&) [5]) const Line | Count | Source | 268 | 2.10k | { | 269 | 2.10k | return EqualsASCII(aStr, N - 1); | 270 | 2.10k | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<6>(char const (&) [6]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<4>(char const (&) [4]) const Line | Count | Source | 268 | 5.29k | { | 269 | 5.29k | return EqualsASCII(aStr, N - 1); | 270 | 5.29k | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<22>(char const (&) [22]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<24>(char const (&) [24]) const Line | Count | Source | 268 | 3 | { | 269 | 3 | return EqualsASCII(aStr, N - 1); | 270 | 3 | } |
bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<29>(char const (&) [29]) const Line | Count | Source | 268 | 3 | { | 269 | 3 | return EqualsASCII(aStr, N - 1); | 270 | 3 | } |
bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<20>(char const (&) [20]) const Line | Count | Source | 268 | 3 | { | 269 | 3 | return EqualsASCII(aStr, N - 1); | 270 | 3 | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<23>(char const (&) [23]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<7>(char const (&) [7]) const Line | Count | Source | 268 | 2.33k | { | 269 | 2.33k | return EqualsASCII(aStr, N - 1); | 270 | 2.33k | } |
bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<2>(char const (&) [2]) const Line | Count | Source | 268 | 156 | { | 269 | 156 | return EqualsASCII(aStr, N - 1); | 270 | 156 | } |
bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<3>(char const (&) [3]) const Line | Count | Source | 268 | 69 | { | 269 | 69 | return EqualsASCII(aStr, N - 1); | 270 | 69 | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<16>(char const (&) [16]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<8>(char const (&) [8]) const Line | Count | Source | 268 | 2.73k | { | 269 | 2.73k | return EqualsASCII(aStr, N - 1); | 270 | 2.73k | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<12>(char const (&) [12]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<27>(char const (&) [27]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<22>(char const (&) [22]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<9>(char const (&) [9]) const Line | Count | Source | 268 | 3 | { | 269 | 3 | return EqualsASCII(aStr, N - 1); | 270 | 3 | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<17>(char const (&) [17]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<35>(char const (&) [35]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<10>(char const (&) [10]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<18>(char const (&) [18]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<11>(char const (&) [11]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<31>(char const (&) [31]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<26>(char const (&) [26]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<25>(char const (&) [25]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<19>(char const (&) [19]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<15>(char const (&) [15]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<14>(char const (&) [14]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<28>(char const (&) [28]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<21>(char const (&) [21]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<33>(char const (&) [33]) const bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<1>(char const (&) [1]) const Line | Count | Source | 268 | 316 | { | 269 | 316 | return EqualsASCII(aStr, N - 1); | 270 | 316 | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<23>(char const (&) [23]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<3>(char const (&) [3]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<4>(char const (&) [4]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<16>(char const (&) [16]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<2>(char const (&) [2]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<13>(char const (&) [13]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<30>(char const (&) [30]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<32>(char const (&) [32]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<30>(char const (&) [30]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<26>(char const (&) [26]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<47>(char const (&) [47]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<54>(char const (&) [54]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<21>(char const (&) [21]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<37>(char const (&) [37]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<29>(char const (&) [29]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<38>(char const (&) [38]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<40>(char const (&) [40]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<20>(char const (&) [20]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<1>(char const (&) [1]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<34>(char const (&) [34]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<34>(char const (&) [34]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<31>(char const (&) [31]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<38>(char const (&) [38]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<35>(char const (&) [35]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<41>(char const (&) [41]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<49>(char const (&) [49]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<39>(char const (&) [39]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<33>(char const (&) [33]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<53>(char const (&) [53]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<28>(char const (&) [28]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<37>(char const (&) [37]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<36>(char const (&) [36]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<48>(char const (&) [48]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<41>(char const (&) [41]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<43>(char const (&) [43]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<36>(char const (&) [36]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<39>(char const (&) [39]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<63>(char const (&) [63]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<57>(char const (&) [57]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<51>(char const (&) [51]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<45>(char const (&) [45]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::EqualsLiteral<42>(char const (&) [42]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<312>(char const (&) [312]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::EqualsLiteral<62>(char const (&) [62]) const |
271 | | |
272 | | // The LowerCaseEquals methods compare the ASCII-lowercase version of |
273 | | // this string (lowercasing only ASCII uppercase characters) to some |
274 | | // ASCII/Literal string. The ASCII string is *not* lowercased for |
275 | | // you. If you compare to an ASCII or literal string that contains an |
276 | | // uppercase character, it is guaranteed to return false. We will |
277 | | // throw assertions too. |
278 | | bool NS_FASTCALL LowerCaseEqualsASCII(const char* aData, |
279 | | size_type aLen) const; |
280 | | bool NS_FASTCALL LowerCaseEqualsASCII(const char* aData) const; |
281 | | |
282 | | // LowerCaseEqualsLiteral must ONLY be applied to an actual |
283 | | // literal string, or a char array *constant* declared without an |
284 | | // explicit size. Do not attempt to use it with a regular char* |
285 | | // pointer, or with a non-constant char array variable. Use |
286 | | // LowerCaseEqualsASCII for them. |
287 | | template<int N> |
288 | | bool LowerCaseEqualsLiteral(const char (&aStr)[N]) const |
289 | 14.0M | { |
290 | 14.0M | return LowerCaseEqualsASCII(aStr, N - 1); |
291 | 14.0M | } Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<9>(char const (&) [9]) const bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<6>(char const (&) [6]) const Line | Count | Source | 289 | 1.70M | { | 290 | 1.70M | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 1.70M | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<11>(char const (&) [11]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<10>(char const (&) [10]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<8>(char const (&) [8]) const bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<5>(char const (&) [5]) const Line | Count | Source | 289 | 5.54M | { | 290 | 5.54M | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 5.54M | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<8>(char const (&) [8]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<5>(char const (&) [5]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<6>(char const (&) [6]) const bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<2>(char const (&) [2]) const Line | Count | Source | 289 | 30 | { | 290 | 30 | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 30 | } |
bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<7>(char const (&) [7]) const Line | Count | Source | 289 | 1.67M | { | 290 | 1.67M | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 1.67M | } |
bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<9>(char const (&) [9]) const Line | Count | Source | 289 | 2.06k | { | 290 | 2.06k | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 2.06k | } |
bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<22>(char const (&) [22]) const Line | Count | Source | 289 | 1.03k | { | 290 | 1.03k | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 1.03k | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<7>(char const (&) [7]) const bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<4>(char const (&) [4]) const Line | Count | Source | 289 | 3.38M | { | 290 | 3.38M | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 3.38M | } |
bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<3>(char const (&) [3]) const Line | Count | Source | 289 | 1.70M | { | 290 | 1.70M | return LowerCaseEqualsASCII(aStr, N - 1); | 291 | 1.70M | } |
Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<24>(char const (&) [24]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<12>(char const (&) [12]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<18>(char const (&) [18]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<10>(char const (&) [10]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<11>(char const (&) [11]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<14>(char const (&) [14]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<34>(char const (&) [34]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<20>(char const (&) [20]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<16>(char const (&) [16]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<13>(char const (&) [13]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<12>(char const (&) [12]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<13>(char const (&) [13]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<17>(char const (&) [17]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<18>(char const (&) [18]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<4>(char const (&) [4]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<3>(char const (&) [3]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<15>(char const (&) [15]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<23>(char const (&) [23]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<16>(char const (&) [16]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<19>(char const (&) [19]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<19>(char const (&) [19]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<26>(char const (&) [26]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<25>(char const (&) [25]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char16_t>::LowerCaseEqualsLiteral<21>(char const (&) [21]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<23>(char const (&) [23]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<29>(char const (&) [29]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<33>(char const (&) [33]) const Unexecuted instantiation: bool mozilla::detail::nsTStringRepr<char>::LowerCaseEqualsLiteral<27>(char const (&) [27]) const |
292 | | |
293 | | // Returns true if this string overlaps with the given string fragment. |
294 | | bool IsDependentOn(const char_type* aStart, const char_type* aEnd) const |
295 | | { |
296 | | // If it _isn't_ the case that one fragment starts after the other ends, |
297 | | // or ends before the other starts, then, they conflict: |
298 | | // |
299 | | // !(f2.begin >= f1.aEnd || f2.aEnd <= f1.begin) |
300 | | // |
301 | | // Simplified, that gives us (To avoid relying on Undefined Behavior |
302 | | // from comparing pointers from different allocations (which in |
303 | | // principle gives the optimizer the permission to assume elsewhere |
304 | | // that the pointers are from the same allocation), the comparisons |
305 | | // are done on integers, which merely relies on implementation-defined |
306 | | // behavior of converting pointers to integers. std::less and |
307 | | // std::greater implementations don't actually provide the guarantees |
308 | | // that they should.): |
309 | | return (reinterpret_cast<uintptr_t>(aStart) < |
310 | | reinterpret_cast<uintptr_t>(mData + mLength) && |
311 | | reinterpret_cast<uintptr_t>(aEnd) > |
312 | | reinterpret_cast<uintptr_t>(mData)); |
313 | | } |
314 | | |
315 | | protected: |
316 | | nsTStringRepr() = delete; // Never instantiate directly |
317 | | |
318 | | constexpr |
319 | | nsTStringRepr(char_type* aData, size_type aLength, |
320 | | DataFlags aDataFlags, ClassFlags aClassFlags) |
321 | | : mData(aData) |
322 | | , mLength(aLength) |
323 | | , mDataFlags(aDataFlags) |
324 | | , mClassFlags(aClassFlags) |
325 | 213M | { |
326 | 213M | } mozilla::detail::nsTStringRepr<char>::nsTStringRepr(char*, unsigned int, mozilla::detail::StringDataFlags, mozilla::detail::StringClassFlags) Line | Count | Source | 325 | 195M | { | 326 | 195M | } |
mozilla::detail::nsTStringRepr<char16_t>::nsTStringRepr(char16_t*, unsigned int, mozilla::detail::StringDataFlags, mozilla::detail::StringClassFlags) Line | Count | Source | 325 | 17.3M | { | 326 | 17.3M | } |
|
327 | | |
328 | | char_type* mData; |
329 | | size_type mLength; |
330 | | DataFlags mDataFlags; |
331 | | ClassFlags const mClassFlags; |
332 | | }; |
333 | | |
334 | | extern template class nsTStringRepr<char>; |
335 | | extern template class nsTStringRepr<char16_t>; |
336 | | |
337 | | } // namespace detail |
338 | | } // namespace mozilla |
339 | | |
340 | | template <typename T> |
341 | | int NS_FASTCALL |
342 | | Compare(const mozilla::detail::nsTStringRepr<T>& aLhs, |
343 | | const mozilla::detail::nsTStringRepr<T>& aRhs, |
344 | | const nsTStringComparator<T>& = nsTDefaultStringComparator<T>()); |
345 | | |
346 | | template <typename T> |
347 | | inline bool |
348 | | operator!=(const mozilla::detail::nsTStringRepr<T>& aLhs, |
349 | | const mozilla::detail::nsTStringRepr<T>& aRhs) |
350 | 0 | { |
351 | 0 | return !aLhs.Equals(aRhs); |
352 | 0 | } Unexecuted instantiation: bool operator!=<char16_t>(mozilla::detail::nsTStringRepr<char16_t> const&, mozilla::detail::nsTStringRepr<char16_t> const&) Unexecuted instantiation: bool operator!=<char>(mozilla::detail::nsTStringRepr<char> const&, mozilla::detail::nsTStringRepr<char> const&) |
353 | | |
354 | | template <typename T> |
355 | | inline bool |
356 | | operator!=(const mozilla::detail::nsTStringRepr<T>& aLhs, |
357 | | const T* aRhs) |
358 | 0 | { |
359 | 0 | return !aLhs.Equals(aRhs); |
360 | 0 | } Unexecuted instantiation: bool operator!=<char>(mozilla::detail::nsTStringRepr<char> const&, char const*) Unexecuted instantiation: bool operator!=<char16_t>(mozilla::detail::nsTStringRepr<char16_t> const&, char16_t const*) |
361 | | |
362 | | template <typename T> |
363 | | inline bool |
364 | | operator<(const mozilla::detail::nsTStringRepr<T>& aLhs, |
365 | | const mozilla::detail::nsTStringRepr<T>& aRhs) |
366 | 3 | { |
367 | 3 | return Compare(aLhs, aRhs) < 0; |
368 | 3 | } Unexecuted instantiation: bool operator< <char16_t>(mozilla::detail::nsTStringRepr<char16_t> const&, mozilla::detail::nsTStringRepr<char16_t> const&) bool operator< <char>(mozilla::detail::nsTStringRepr<char> const&, mozilla::detail::nsTStringRepr<char> const&) Line | Count | Source | 366 | 3 | { | 367 | 3 | return Compare(aLhs, aRhs) < 0; | 368 | 3 | } |
|
369 | | |
370 | | template <typename T> |
371 | | inline bool |
372 | | operator<=(const mozilla::detail::nsTStringRepr<T>& aLhs, |
373 | | const mozilla::detail::nsTStringRepr<T>& aRhs) |
374 | 0 | { |
375 | 0 | return Compare(aLhs, aRhs) <= 0; |
376 | 0 | } |
377 | | |
378 | | template <typename T> |
379 | | inline bool |
380 | | operator==(const mozilla::detail::nsTStringRepr<T>& aLhs, |
381 | | const mozilla::detail::nsTStringRepr<T>& aRhs) |
382 | 1.20M | { |
383 | 1.20M | return aLhs.Equals(aRhs); |
384 | 1.20M | } Unexecuted instantiation: bool operator==<char16_t>(mozilla::detail::nsTStringRepr<char16_t> const&, mozilla::detail::nsTStringRepr<char16_t> const&) bool operator==<char>(mozilla::detail::nsTStringRepr<char> const&, mozilla::detail::nsTStringRepr<char> const&) Line | Count | Source | 382 | 1.20M | { | 383 | 1.20M | return aLhs.Equals(aRhs); | 384 | 1.20M | } |
|
385 | | |
386 | | template <typename T> |
387 | | inline bool |
388 | | operator==(const mozilla::detail::nsTStringRepr<T>& aLhs, |
389 | | const T* aRhs) |
390 | 0 | { |
391 | 0 | return aLhs.Equals(aRhs); |
392 | 0 | } |
393 | | |
394 | | template <typename T> |
395 | | inline bool |
396 | | operator>=(const mozilla::detail::nsTStringRepr<T>& aLhs, |
397 | | const mozilla::detail::nsTStringRepr<T>& aRhs) |
398 | | { |
399 | | return Compare(aLhs, aRhs) >= 0; |
400 | | } |
401 | | |
402 | | template <typename T> |
403 | | inline bool |
404 | | operator>(const mozilla::detail::nsTStringRepr<T>& aLhs, |
405 | | const mozilla::detail::nsTStringRepr<T>& aRhs) |
406 | | { |
407 | | return Compare(aLhs, aRhs) > 0; |
408 | | } |
409 | | |
410 | | #endif |