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 #include "nsTDependentString.h"
10 nsTDependentString
<T
>::nsTDependentString(const char_type
* aStart
,
11 const char_type
* aEnd
)
12 : string_type(const_cast<char_type
*>(aStart
), aEnd
- aStart
,
13 DataFlags::TERMINATED
, ClassFlags(0)) {
14 MOZ_RELEASE_ASSERT(aStart
<= aEnd
, "Overflow!");
15 this->AssertValidDependentString();
19 void nsTDependentString
<T
>::Rebind(const string_type
& str
,
20 index_type startPos
) {
21 MOZ_ASSERT(str
.GetDataFlags() & DataFlags::TERMINATED
,
22 "Unterminated flat string");
24 // If we currently own a buffer, release it.
27 size_type strLength
= str
.Length();
29 if (startPos
> strLength
) {
34 const_cast<char_type
*>(static_cast<const char_type
*>(str
.Data())) +
36 size_type newLen
= strLength
- startPos
;
37 DataFlags newDataFlags
=
38 str
.GetDataFlags() & (DataFlags::TERMINATED
| DataFlags::LITERAL
);
39 this->SetData(newData
, newLen
, newDataFlags
);
43 void nsTDependentString
<T
>::Rebind(const char_type
* aStart
,
44 const char_type
* aEnd
) {
45 MOZ_RELEASE_ASSERT(aStart
<= aEnd
, "Overflow!");
46 this->Rebind(aStart
, aEnd
- aStart
);
49 template class nsTDependentString
<char>;
50 template class nsTDependentString
<char16_t
>;