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 void
8 nsTDependentSubstring_CharT::Rebind(const substring_type& str,
9                                     uint32_t startPos, uint32_t length)
10 {
11   // If we currently own a buffer, release it.
12   Finalize();
13 
14   size_type strLength = str.Length();
15 
16   if (startPos > strLength) {
17     startPos = strLength;
18   }
19 
20   mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
21   mLength = XPCOM_MIN(length, strLength - startPos);
22 
23   SetDataFlags(F_NONE);
24 }
25 
26 void
27 nsTDependentSubstring_CharT::Rebind(const char_type* data, size_type length)
28 {
29   NS_ASSERTION(data, "nsTDependentSubstring must wrap a non-NULL buffer");
30 
31   // If we currently own a buffer, release it.
32   Finalize();
33 
34   mData = const_cast<char_type*>(static_cast<const char_type*>(data));
35   mLength = length;
36   SetDataFlags(F_NONE);
37 }
38