/src/mozilla-central/xpcom/string/nsTDependentSubstring.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 | | // IWYU pragma: private, include "nsString.h" |
7 | | |
8 | | #ifndef nsTDependentSubstring_h |
9 | | #define nsTDependentSubstring_h |
10 | | |
11 | | #include "nsTSubstring.h" |
12 | | #include "nsTLiteralString.h" |
13 | | |
14 | | /** |
15 | | * nsTDependentSubstring_CharT |
16 | | * |
17 | | * A string class which wraps an external array of string characters. It |
18 | | * is the client code's responsibility to ensure that the external buffer |
19 | | * remains valid for a long as the string is alive. |
20 | | * |
21 | | * NAMES: |
22 | | * nsDependentSubstring for wide characters |
23 | | * nsDependentCSubstring for narrow characters |
24 | | */ |
25 | | template <typename T> |
26 | | class nsTDependentSubstring : public nsTSubstring<T> |
27 | | { |
28 | | public: |
29 | | |
30 | | typedef nsTDependentSubstring<T> self_type; |
31 | | typedef nsTSubstring<T> substring_type; |
32 | | typedef typename substring_type::fallible_t fallible_t; |
33 | | |
34 | | typedef typename substring_type::char_type char_type; |
35 | | typedef typename substring_type::char_traits char_traits; |
36 | | typedef typename substring_type::incompatible_char_type incompatible_char_type; |
37 | | |
38 | | typedef typename substring_type::substring_tuple_type substring_tuple_type; |
39 | | |
40 | | typedef typename substring_type::const_iterator const_iterator; |
41 | | typedef typename substring_type::iterator iterator; |
42 | | |
43 | | typedef typename substring_type::comparator_type comparator_type; |
44 | | |
45 | | typedef typename substring_type::const_char_iterator const_char_iterator; |
46 | | |
47 | | typedef typename substring_type::index_type index_type; |
48 | | typedef typename substring_type::size_type size_type; |
49 | | |
50 | | // These are only for internal use within the string classes: |
51 | | typedef typename substring_type::DataFlags DataFlags; |
52 | | typedef typename substring_type::ClassFlags ClassFlags; |
53 | | |
54 | | public: |
55 | | |
56 | | void Rebind(const substring_type&, uint32_t aStartPos, |
57 | | uint32_t aLength = size_type(-1)); |
58 | | |
59 | | void Rebind(const char_type* aData, size_type aLength); |
60 | | |
61 | | void Rebind(const char_type* aStart, const char_type* aEnd); |
62 | | |
63 | | nsTDependentSubstring(const substring_type& aStr, uint32_t aStartPos, |
64 | | uint32_t aLength = size_type(-1)) |
65 | | : substring_type() |
66 | 124k | { |
67 | 124k | Rebind(aStr, aStartPos, aLength); |
68 | 124k | } |
69 | | |
70 | | nsTDependentSubstring(const char_type* aData, size_type aLength) |
71 | | : substring_type(const_cast<char_type*>(aData), aLength, |
72 | | DataFlags(0), ClassFlags(0)) |
73 | 0 | { |
74 | 0 | } |
75 | | |
76 | | nsTDependentSubstring(const char_type* aStart, const char_type* aEnd); |
77 | | |
78 | | #if defined(MOZ_USE_CHAR16_WRAPPER) |
79 | | template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>> |
80 | | nsTDependentSubstring(char16ptr_t aData, size_type aLength) |
81 | | : nsTDependentSubstring(static_cast<const char16_t*>(aData), aLength) |
82 | | { |
83 | | } |
84 | | |
85 | | template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>> |
86 | | nsTDependentSubstring(char16ptr_t aStart, char16ptr_t aEnd); |
87 | | #endif |
88 | | |
89 | | nsTDependentSubstring(const const_iterator& aStart, |
90 | | const const_iterator& aEnd); |
91 | | |
92 | | // Create a nsTDependentSubstring to be bound later |
93 | | nsTDependentSubstring() |
94 | | : substring_type() |
95 | 56.0M | { |
96 | 56.0M | } nsTDependentSubstring<char>::nsTDependentSubstring() Line | Count | Source | 95 | 56.0M | { | 96 | 56.0M | } |
Unexecuted instantiation: nsTDependentSubstring<char16_t>::nsTDependentSubstring() |
97 | | |
98 | | // auto-generated copy-constructor OK (XXX really?? what about base class copy-ctor?) |
99 | | |
100 | | private: |
101 | | // NOT USED |
102 | | void operator=(const self_type&); // we're immutable, you can't assign into a substring |
103 | | }; |
104 | | |
105 | | extern template class nsTDependentSubstring<char>; |
106 | | extern template class nsTDependentSubstring<char16_t>; |
107 | | |
108 | | template <typename T> |
109 | | inline const nsTDependentSubstring<T> |
110 | | Substring(const nsTSubstring<T>& aStr, uint32_t aStartPos, |
111 | | uint32_t aLength = uint32_t(-1)) |
112 | 124k | { |
113 | 124k | return nsTDependentSubstring<T>(aStr, aStartPos, aLength); |
114 | 124k | } |
115 | | |
116 | | template <typename T> |
117 | | inline const nsTDependentSubstring<T> |
118 | | Substring(const nsTLiteralString<T>& aStr, uint32_t aStartPos, |
119 | | uint32_t aLength = uint32_t(-1)) |
120 | | { |
121 | | return nsTDependentSubstring<T>(aStr, aStartPos, aLength); |
122 | | } |
123 | | |
124 | | template <typename T> |
125 | | inline const nsTDependentSubstring<T> |
126 | | Substring(const nsReadingIterator<T>& aStart, |
127 | | const nsReadingIterator<T>& aEnd) |
128 | | { |
129 | | return nsTDependentSubstring<T>(aStart.get(), aEnd.get()); |
130 | | } |
131 | | |
132 | | template <typename T> |
133 | | inline const nsTDependentSubstring<T> |
134 | | Substring(const T* aData, uint32_t aLength) |
135 | | { |
136 | | return nsTDependentSubstring<T>(aData, aLength); |
137 | | } |
138 | | |
139 | | template <typename T> |
140 | | const nsTDependentSubstring<T> |
141 | | Substring(const T* aStart, const T* aEnd); |
142 | | |
143 | | #if defined(MOZ_USE_CHAR16_WRAPPER) |
144 | | inline const nsTDependentSubstring<char16_t> |
145 | | Substring(char16ptr_t aData, uint32_t aLength); |
146 | | |
147 | | const nsTDependentSubstring<char16_t> |
148 | | Substring(char16ptr_t aStart, char16ptr_t aEnd); |
149 | | #endif |
150 | | |
151 | | template <typename T> |
152 | | inline const nsTDependentSubstring<T> |
153 | | StringHead(const nsTSubstring<T>& aStr, uint32_t aCount) |
154 | | { |
155 | | return nsTDependentSubstring<T>(aStr, 0, aCount); |
156 | | } |
157 | | |
158 | | template <typename T> |
159 | | inline const nsTDependentSubstring<T> |
160 | | StringTail(const nsTSubstring<T>& aStr, uint32_t aCount) |
161 | | { |
162 | | return nsTDependentSubstring<T>(aStr, aStr.Length() - aCount, aCount); |
163 | | } |
164 | | |
165 | | #endif |