Bug 1777320 [wpt PR 34649] - Update CSS toggles parsing/computation code to spec...
[gecko.git] / xpcom / string / nsTDependentString.h
blob5c2116370de1aac7c30da0f832ee94933a30d0e5
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/. */
7 #ifndef nsTDependentString_h
8 #define nsTDependentString_h
10 #include "nsTString.h"
12 /**
13 * nsTDependentString
15 * Stores a null-terminated, immutable sequence of characters.
17 * Subclass of nsTString that restricts string value to an immutable
18 * character sequence. This class does not own its data, so the creator
19 * of objects of this type must take care to ensure that a
20 * nsTDependentString continues to reference valid memory for the
21 * duration of its use.
23 template <typename T>
24 class nsTDependentString : public nsTString<T> {
25 public:
26 typedef nsTDependentString<T> self_type;
27 typedef nsTString<T> base_string_type;
28 typedef typename base_string_type::string_type string_type;
30 typedef typename base_string_type::fallible_t fallible_t;
32 typedef typename base_string_type::char_type char_type;
33 typedef typename base_string_type::char_traits char_traits;
34 typedef
35 typename base_string_type::incompatible_char_type incompatible_char_type;
37 typedef typename base_string_type::substring_tuple_type substring_tuple_type;
39 typedef typename base_string_type::const_iterator const_iterator;
40 typedef typename base_string_type::iterator iterator;
42 typedef typename base_string_type::comparator_type comparator_type;
44 typedef typename base_string_type::const_char_iterator const_char_iterator;
46 typedef typename base_string_type::index_type index_type;
47 typedef typename base_string_type::size_type size_type;
49 // These are only for internal use within the string classes:
50 typedef typename base_string_type::DataFlags DataFlags;
51 typedef typename base_string_type::ClassFlags ClassFlags;
53 public:
54 /**
55 * constructors
58 nsTDependentString(const char_type* aStart, const char_type* aEnd);
60 nsTDependentString(const char_type* aData, size_type aLength)
61 : string_type(const_cast<char_type*>(aData), aLength,
62 DataFlags::TERMINATED, ClassFlags(0)) {
63 this->AssertValidDependentString();
66 #if defined(MOZ_USE_CHAR16_WRAPPER)
67 template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
68 nsTDependentString(char16ptr_t aData, size_type aLength)
69 : nsTDependentString(static_cast<const char16_t*>(aData), aLength) {}
70 #endif
72 explicit nsTDependentString(const char_type* aData)
73 : string_type(const_cast<char_type*>(aData), char_traits::length(aData),
74 DataFlags::TERMINATED, ClassFlags(0)) {
75 string_type::AssertValidDependentString();
78 #if defined(MOZ_USE_CHAR16_WRAPPER)
79 template <typename Q = T, typename EnableIfChar16 = mozilla::Char16OnlyT<Q>>
80 explicit nsTDependentString(char16ptr_t aData)
81 : nsTDependentString(static_cast<const char16_t*>(aData)) {}
82 #endif
84 nsTDependentString(const string_type& aStr, index_type aStartPos)
85 : string_type() {
86 Rebind(aStr, aStartPos);
89 // Create a nsTDependentSubstring to be bound later
90 nsTDependentString() : string_type() {}
92 // auto-generated destructor OK
94 nsTDependentString(self_type&& aStr) : string_type() {
95 Rebind(aStr, /* aStartPos = */ 0);
96 aStr.SetToEmptyBuffer();
99 explicit nsTDependentString(const self_type& aStr) : string_type() {
100 Rebind(aStr, /* aStartPos = */ 0);
104 * allow this class to be bound to a different string...
107 using nsTString<T>::Rebind;
108 void Rebind(const char_type* aData) {
109 Rebind(aData, char_traits::length(aData));
112 void Rebind(const char_type* aStart, const char_type* aEnd);
113 void Rebind(const string_type&, index_type aStartPos);
115 private:
116 // NOT USED
117 nsTDependentString(const substring_tuple_type&) = delete;
118 self_type& operator=(const self_type& aStr) = delete;
121 extern template class nsTDependentString<char>;
122 extern template class nsTDependentString<char16_t>;
124 #endif