2014-05-05 21:30:46 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-01-21 07:39:58 +03:00
|
|
|
|
2017-12-22 18:53:12 +03:00
|
|
|
#include "nsTDependentSubstring.h"
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
2004-02-19 05:44:03 +03:00
|
|
|
void
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTDependentSubstring<T>::Rebind(const substring_type& str,
|
2014-05-27 11:15:35 +04:00
|
|
|
uint32_t startPos, uint32_t length)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
// If we currently own a buffer, release it.
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Finalize();
|
2004-11-25 10:03:20 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
size_type strLength = str.Length();
|
2004-01-21 07:39:58 +03:00
|
|
|
|
2014-05-27 11:15:35 +04:00
|
|
|
if (startPos > strLength) {
|
2014-05-05 21:30:46 +04:00
|
|
|
startPos = strLength;
|
2014-05-27 11:15:35 +04:00
|
|
|
}
|
2004-01-21 07:39:58 +03:00
|
|
|
|
2017-07-21 01:46:59 +03:00
|
|
|
char_type* newData =
|
|
|
|
const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
|
|
|
|
size_type newLength = XPCOM_MIN(length, strLength - startPos);
|
|
|
|
DataFlags newDataFlags = DataFlags(0);
|
2017-08-15 00:22:50 +03:00
|
|
|
this->SetData(newData, newLength, newDataFlags);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2004-11-25 10:03:20 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
2004-11-25 10:03:20 +03:00
|
|
|
void
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTDependentSubstring<T>::Rebind(const char_type* data, size_type length)
|
2014-05-05 21:30:46 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(data, "nsTDependentSubstring must wrap a non-NULL buffer");
|
2004-11-25 10:03:20 +03:00
|
|
|
|
2014-05-05 21:30:46 +04:00
|
|
|
// If we currently own a buffer, release it.
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Finalize();
|
2004-11-25 10:03:20 +03:00
|
|
|
|
2017-07-21 01:46:59 +03:00
|
|
|
char_type* newData =
|
|
|
|
const_cast<char_type*>(static_cast<const char_type*>(data));
|
|
|
|
size_type newLength = length;
|
|
|
|
DataFlags newDataFlags = DataFlags(0);
|
2017-08-15 00:22:50 +03:00
|
|
|
this->SetData(newData, newLength, newDataFlags);
|
2014-05-05 21:30:46 +04:00
|
|
|
}
|
2017-02-21 19:38:00 +03:00
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
2017-02-21 19:38:00 +03:00
|
|
|
void
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTDependentSubstring<T>::Rebind(const char_type* aStart, const char_type* aEnd)
|
2017-02-21 19:38:00 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
|
2017-08-15 00:22:50 +03:00
|
|
|
this->Rebind(aStart, size_type(aEnd - aStart));
|
2017-02-21 19:38:00 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
|
|
|
nsTDependentSubstring<T>::nsTDependentSubstring(const char_type* aStart,
|
|
|
|
const char_type* aEnd)
|
2017-02-21 19:38:00 +03:00
|
|
|
: substring_type(const_cast<char_type*>(aStart), uint32_t(aEnd - aStart),
|
2017-07-10 22:23:10 +03:00
|
|
|
DataFlags(0), ClassFlags(0))
|
2017-02-21 19:38:00 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
|
|
|
|
}
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
|
|
|
template <typename T>
|
2017-10-03 22:44:44 +03:00
|
|
|
template <typename Q, typename EnableIfChar16>
|
2017-08-15 00:22:50 +03:00
|
|
|
nsTDependentSubstring<T>::nsTDependentSubstring(char16ptr_t aStart,
|
|
|
|
char16ptr_t aEnd)
|
|
|
|
: substring_type(static_cast<const char16_t*>(aStart),
|
|
|
|
static_cast<const char16_t*>(aEnd))
|
2017-02-21 19:38:00 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(static_cast<const char16_t*>(aStart) <=
|
|
|
|
static_cast<const char16_t*>(aEnd),
|
|
|
|
"Overflow!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
|
|
|
nsTDependentSubstring<T>::nsTDependentSubstring(const const_iterator& aStart,
|
|
|
|
const const_iterator& aEnd)
|
2017-02-21 19:38:00 +03:00
|
|
|
: substring_type(const_cast<char_type*>(aStart.get()),
|
2017-07-10 22:23:10 +03:00
|
|
|
uint32_t(aEnd.get() - aStart.get()),
|
|
|
|
DataFlags(0), ClassFlags(0))
|
2017-02-21 19:38:00 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aStart.get() <= aEnd.get(), "Overflow!");
|
|
|
|
}
|
|
|
|
|
2017-08-15 00:22:50 +03:00
|
|
|
template <typename T>
|
|
|
|
const nsTDependentSubstring<T>
|
|
|
|
Substring(const T* aStart, const T* aEnd)
|
2017-02-21 19:38:00 +03:00
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aStart <= aEnd, "Overflow!");
|
2017-08-15 00:22:50 +03:00
|
|
|
return nsTDependentSubstring<T>(aStart, aEnd);
|
2017-02-21 19:38:00 +03:00
|
|
|
}
|
2017-08-15 00:22:50 +03:00
|
|
|
|
|
|
|
#if defined(MOZ_USE_CHAR16_WRAPPER)
|
|
|
|
const nsTDependentSubstring<char16_t>
|
|
|
|
Substring(char16ptr_t aData, uint32_t aLength)
|
|
|
|
{
|
|
|
|
return nsTDependentSubstring<char16_t>(aData, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsTDependentSubstring<char16_t>
|
|
|
|
Substring(char16ptr_t aStart, char16ptr_t aEnd)
|
|
|
|
{
|
|
|
|
return Substring(static_cast<const char16_t*>(aStart),
|
|
|
|
static_cast<const char16_t*>(aEnd));
|
|
|
|
}
|
|
|
|
#endif
|