Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / xpcom / string / nsTDependentString.cpp
blob83cfa3968737a90b4570736cf9afd4b57517e8ab
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"
9 template <typename T>
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();
18 template <typename T>
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.
25 this->Finalize();
27 size_type strLength = str.Length();
29 if (startPos > strLength) {
30 startPos = strLength;
33 char_type* newData =
34 const_cast<char_type*>(static_cast<const char_type*>(str.Data())) +
35 startPos;
36 size_type newLen = strLength - startPos;
37 DataFlags newDataFlags =
38 str.GetDataFlags() & (DataFlags::TERMINATED | DataFlags::LITERAL);
39 this->SetData(newData, newLen, newDataFlags);
42 template <typename T>
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>;