2014-05-05 17:30:46 +00: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 11:12:37 +00: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/. */
|
2014-09-17 06:33:05 +00:00
|
|
|
|
|
|
|
#include "mozilla/double-conversion.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-09-24 17:36:55 +00:00
|
|
|
|
|
|
|
using double_conversion::DoubleToStringConverter;
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2010-08-07 00:46:51 +00:00
|
|
|
#ifdef XPCOM_STRING_CONSTRUCTOR_OUT_OF_LINE
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::nsTSubstring_CharT(char_type* aData, size_type aLength,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: mData(aData),
|
|
|
|
mLength(aLength),
|
|
|
|
mFlags(aFlags)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aFlags & F_OWNED) {
|
2014-05-05 17:30:46 +00:00
|
|
|
STRING_STAT_INCREMENT(Adopt);
|
2006-11-10 20:05:04 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_LogCtor(mData, "StringAdopt", 1);
|
2006-11-10 20:05:04 +00:00
|
|
|
#endif
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2010-08-07 00:46:51 +00:00
|
|
|
#endif /* XPCOM_STRING_CONSTRUCTOR_OUT_OF_LINE */
|
2008-08-18 15:40:49 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
/**
|
|
|
|
* helper function for down-casting a nsTSubstring to a nsTFixedString.
|
|
|
|
*/
|
2004-02-20 01:53:23 +00:00
|
|
|
inline const nsTFixedString_CharT*
|
2014-05-27 07:15:35 +00:00
|
|
|
AsFixedString(const nsTSubstring_CharT* aStr)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return static_cast<const nsTFixedString_CharT*>(aStr);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-20 01:53:23 +00:00
|
|
|
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
/**
|
|
|
|
* this function is called to prepare mData for writing. the given capacity
|
|
|
|
* indicates the required minimum storage size for mData, in sizeof(char_type)
|
|
|
|
* increments. this function returns true if the operation succeeds. it also
|
|
|
|
* returns the old data and old flags members if mData is newly allocated.
|
|
|
|
* the old data must be released by the caller.
|
|
|
|
*/
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::MutatePrep(size_type aCapacity, char_type** aOldData,
|
|
|
|
uint32_t* aOldFlags)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// initialize to no old data
|
2014-05-27 07:15:35 +00:00
|
|
|
*aOldData = nullptr;
|
|
|
|
*aOldFlags = 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
|
|
|
|
size_type curCapacity = Capacity();
|
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
// If |aCapacity > kMaxCapacity|, then our doubling algorithm may not be
|
2014-05-05 17:30:46 +00:00
|
|
|
// able to allocate it. Just bail out in cases like that. We don't want
|
|
|
|
// to be allocating 2GB+ strings anyway.
|
|
|
|
PR_STATIC_ASSERT((sizeof(nsStringBuffer) & 0x1) == 0);
|
|
|
|
const size_type kMaxCapacity =
|
2014-05-27 07:15:35 +00:00
|
|
|
(size_type(-1) / 2 - sizeof(nsStringBuffer)) / sizeof(char_type) - 2;
|
|
|
|
if (aCapacity > kMaxCapacity) {
|
|
|
|
// Also assert for |aCapacity| equal to |size_type(-1)|, since we used to
|
2014-05-05 17:30:46 +00:00
|
|
|
// use that value to flag immutability.
|
2014-05-27 07:15:35 +00:00
|
|
|
NS_ASSERTION(aCapacity != size_type(-1), "Bogus capacity");
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// |curCapacity == 0| means that the buffer is immutable or 0-sized, so we
|
|
|
|
// need to allocate a new buffer. We cannot use the existing buffer even
|
|
|
|
// though it might be large enough.
|
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (curCapacity != 0) {
|
|
|
|
if (aCapacity <= curCapacity) {
|
2014-05-05 17:30:46 +00:00
|
|
|
mFlags &= ~F_VOIDED; // mutation clears voided flag
|
|
|
|
return true;
|
2004-10-19 21:46:45 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// Use doubling algorithm when forced to increase available capacity.
|
|
|
|
size_type temp = curCapacity;
|
2014-05-27 07:15:35 +00:00
|
|
|
while (temp < aCapacity) {
|
2014-05-05 17:30:46 +00:00
|
|
|
temp <<= 1;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
|
|
|
NS_ASSERTION(XPCOM_MIN(temp, kMaxCapacity) >= aCapacity,
|
2014-05-05 17:30:46 +00:00
|
|
|
"should have hit the early return at the top");
|
2014-05-27 07:15:35 +00:00
|
|
|
aCapacity = XPCOM_MIN(temp, kMaxCapacity);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
//
|
|
|
|
// several cases:
|
|
|
|
//
|
|
|
|
// (1) we have a shared buffer (mFlags & F_SHARED)
|
|
|
|
// (2) we have an owned buffer (mFlags & F_OWNED)
|
|
|
|
// (3) we have a fixed buffer (mFlags & F_FIXED)
|
|
|
|
// (4) we have a readonly buffer
|
|
|
|
//
|
|
|
|
// requiring that we in some cases preserve the data before creating
|
|
|
|
// a new buffer complicates things just a bit ;-)
|
|
|
|
//
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type storageSize = (aCapacity + 1) * sizeof(char_type);
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// case #1
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mFlags & F_SHARED) {
|
2014-05-05 17:30:46 +00:00
|
|
|
nsStringBuffer* hdr = nsStringBuffer::FromData(mData);
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!hdr->IsReadonly()) {
|
|
|
|
nsStringBuffer* newHdr = nsStringBuffer::Realloc(hdr, storageSize);
|
|
|
|
if (!newHdr) {
|
|
|
|
return false; // out-of-memory (original header left intact)
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
hdr = newHdr;
|
2014-05-27 07:15:35 +00:00
|
|
|
mData = (char_type*)hdr->Data();
|
2014-05-05 17:30:46 +00:00
|
|
|
mFlags &= ~F_VOIDED; // mutation clears voided flag
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
char_type* newData;
|
|
|
|
uint32_t newDataFlags;
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// if we have a fixed buffer of sufficient size, then use it. this helps
|
|
|
|
// avoid heap allocations.
|
2014-05-27 07:15:35 +00:00
|
|
|
if ((mFlags & F_CLASS_FIXED) &&
|
|
|
|
(aCapacity < AsFixedString(this)->mFixedCapacity)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
newData = AsFixedString(this)->mFixedBuf;
|
|
|
|
newDataFlags = F_TERMINATED | F_FIXED;
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2014-05-05 17:30:46 +00:00
|
|
|
// if we reach here then, we must allocate a new buffer. we cannot
|
|
|
|
// make use of our F_OWNED or F_FIXED buffers because they are not
|
|
|
|
// large enough.
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
nsStringBuffer* newHdr =
|
|
|
|
nsStringBuffer::Alloc(storageSize).take();
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!newHdr) {
|
|
|
|
return false; // we are still in a consistent state
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
newData = (char_type*)newHdr->Data();
|
2014-05-05 17:30:46 +00:00
|
|
|
newDataFlags = F_TERMINATED | F_SHARED;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// save old data and flags
|
2014-05-27 07:15:35 +00:00
|
|
|
*aOldData = mData;
|
|
|
|
*aOldFlags = mFlags;
|
2014-05-05 17:30:46 +00:00
|
|
|
|
|
|
|
mData = newData;
|
|
|
|
SetDataFlags(newDataFlags);
|
|
|
|
|
|
|
|
// mLength does not change
|
|
|
|
|
|
|
|
// though we are not necessarily terminated at the moment, now is probably
|
|
|
|
// still the best time to set F_TERMINATED.
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
|
|
|
nsTSubstring_CharT::Finalize()
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
::ReleaseData(mData, mFlags);
|
|
|
|
// mData, mLength, and mFlags are purposefully left dangling
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::ReplacePrepInternal(index_type aCutStart, size_type aCutLen,
|
|
|
|
size_type aFragLen, size_type aNewLen)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
char_type* oldData;
|
|
|
|
uint32_t oldFlags;
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!MutatePrep(aNewLen, &oldData, &oldFlags)) {
|
|
|
|
return false; // out-of-memory
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (oldData) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// determine whether or not we need to copy part of the old string
|
|
|
|
// over to the new string.
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aCutStart > 0) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// copy prefix from old string
|
2014-05-27 07:15:35 +00:00
|
|
|
char_traits::copy(mData, oldData, aCutStart);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2005-02-16 07:20:20 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aCutStart + aCutLen < mLength) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// copy suffix from old string to new offset
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type from = aCutStart + aCutLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
size_type fromLen = mLength - from;
|
2014-05-27 07:15:35 +00:00
|
|
|
uint32_t to = aCutStart + aFragLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
char_traits::copy(mData + to, oldData + from, fromLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
::ReleaseData(oldData, oldFlags);
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2014-05-05 17:30:46 +00:00
|
|
|
// original data remains intact
|
|
|
|
|
|
|
|
// determine whether or not we need to move part of the existing string
|
|
|
|
// to make room for the requested hole.
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aFragLen != aCutLen && aCutStart + aCutLen < mLength) {
|
|
|
|
uint32_t from = aCutStart + aCutLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
uint32_t fromLen = mLength - from;
|
2014-05-27 07:15:35 +00:00
|
|
|
uint32_t to = aCutStart + aFragLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
char_traits::move(mData + to, mData + from, fromLen);
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// add null terminator (mutable mData always has room for the null-
|
|
|
|
// terminator).
|
2014-05-27 07:15:35 +00:00
|
|
|
mData[aNewLen] = char_type(0);
|
|
|
|
mLength = aNewLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
nsTSubstring_CharT::size_type
|
|
|
|
nsTSubstring_CharT::Capacity() const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// return 0 to indicate an immutable or 0-sized buffer
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
size_type capacity;
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mFlags & F_SHARED) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// if the string is readonly, then we pretend that it has no capacity.
|
|
|
|
nsStringBuffer* hdr = nsStringBuffer::FromData(mData);
|
2014-05-27 07:15:35 +00:00
|
|
|
if (hdr->IsReadonly()) {
|
2014-05-05 17:30:46 +00:00
|
|
|
capacity = 0;
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2014-05-05 17:30:46 +00:00
|
|
|
capacity = (hdr->StorageSize() / sizeof(char_type)) - 1;
|
|
|
|
}
|
2014-05-27 07:15:35 +00:00
|
|
|
} else if (mFlags & F_FIXED) {
|
2014-05-05 17:30:46 +00:00
|
|
|
capacity = AsFixedString(this)->mFixedCapacity;
|
2014-05-27 07:15:35 +00:00
|
|
|
} else if (mFlags & F_OWNED) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// we don't store the capacity of an adopted buffer because that would
|
|
|
|
// require an additional member field. the best we can do is base the
|
|
|
|
// capacity on our length. remains to be seen if this is the right
|
|
|
|
// trade-off.
|
|
|
|
capacity = mLength;
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2014-05-05 17:30:46 +00:00
|
|
|
capacity = 0;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
return capacity;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::EnsureMutable(size_type aNewLen)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aNewLen == size_type(-1) || aNewLen == mLength) {
|
|
|
|
if (mFlags & (F_FIXED | F_OWNED)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
|
|
|
if ((mFlags & F_SHARED) &&
|
|
|
|
!nsStringBuffer::FromData(mData)->IsReadonly()) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
aNewLen = mLength;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
2014-05-27 07:15:35 +00:00
|
|
|
return SetLength(aNewLen, fallible_t());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// This version of Assign is optimized for single-character assignment.
|
2005-10-17 16:28:21 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(char_type aChar)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!ReplacePrep(0, mLength, 1)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_ABORT_OOM(mLength);
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
*mData = aChar;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2005-10-17 16:28:21 +00:00
|
|
|
|
2012-05-08 16:42:27 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(char_type aChar, const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!ReplacePrep(0, mLength, 1)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
*mData = aChar;
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-10-17 16:28:21 +00:00
|
|
|
|
2013-08-20 20:32:54 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const char_type* aData)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!Assign(aData, size_type(-1), fallible_t())) {
|
|
|
|
NS_ABORT_OOM(char_traits::length(aData));
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2013-08-20 20:32:54 +00:00
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!Assign(aData, aLength, fallible_t())) {
|
|
|
|
NS_ABORT_OOM(aLength);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const char_type* aData, size_type aLength,
|
|
|
|
const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!aData || aLength == 0) {
|
2014-05-05 17:30:46 +00:00
|
|
|
Truncate();
|
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aLength == size_type(-1)) {
|
|
|
|
aLength = char_traits::length(aData);
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (IsDependentOn(aData, aData + aLength)) {
|
|
|
|
return Assign(string_type(aData, aLength), fallible_t());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!ReplacePrep(0, mLength, aLength)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
char_traits::copy(mData, aData, aLength);
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2004-06-06 02:17:00 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!AssignASCII(aData, aLength, fallible_t())) {
|
|
|
|
NS_ABORT_OOM(aLength);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::AssignASCII(const char* aData, size_type aLength,
|
|
|
|
const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// A Unicode string can't depend on an ASCII string buffer,
|
|
|
|
// so this dependence check only applies to CStrings.
|
2004-06-06 02:17:00 +00:00
|
|
|
#ifdef CharT_is_char
|
2014-05-27 07:15:35 +00:00
|
|
|
if (IsDependentOn(aData, aData + aLength)) {
|
|
|
|
return Assign(string_type(aData, aLength), fallible_t());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!ReplacePrep(0, mLength, aLength)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
char_traits::copyASCII(mData, aData, aLength);
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
|
2014-01-08 20:51:38 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::AssignLiteral(const char_type* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
::ReleaseData(mData, mFlags);
|
2014-05-27 07:15:35 +00:00
|
|
|
mData = const_cast<char_type*>(aData);
|
|
|
|
mLength = aLength;
|
2014-05-05 17:30:46 +00:00
|
|
|
SetDataFlags(F_TERMINATED | F_LITERAL);
|
|
|
|
}
|
2014-01-08 20:51:38 +00:00
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const self_type& aStr)
|
2012-05-08 16:42:27 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!Assign(aStr, fallible_t())) {
|
|
|
|
NS_ABORT_OOM(aStr.Length());
|
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const self_type& aStr, const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
// |aStr| could be sharable. We need to check its flags to know how to
|
2014-05-05 17:30:46 +00:00
|
|
|
// deal with it.
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (&aStr == this) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!aStr.mLength) {
|
2014-05-05 17:30:46 +00:00
|
|
|
Truncate();
|
2014-05-27 07:15:35 +00:00
|
|
|
mFlags |= aStr.mFlags & F_VOIDED;
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aStr.mFlags & F_SHARED) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// nice! we can avoid a string copy :-)
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
// |aStr| should be null-terminated
|
|
|
|
NS_ASSERTION(aStr.mFlags & F_TERMINATED, "shared, but not terminated");
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
::ReleaseData(mData, mFlags);
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
mData = aStr.mData;
|
|
|
|
mLength = aStr.mLength;
|
2014-05-05 17:30:46 +00:00
|
|
|
SetDataFlags(F_TERMINATED | F_SHARED);
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// get an owning reference to the mData
|
|
|
|
nsStringBuffer::FromData(mData)->AddRef();
|
|
|
|
return true;
|
2014-05-27 07:15:35 +00:00
|
|
|
} else if (aStr.mFlags & F_LITERAL) {
|
|
|
|
NS_ABORT_IF_FALSE(aStr.mFlags & F_TERMINATED, "Unterminated literal");
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
AssignLiteral(aStr.mData, aStr.mLength);
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// else, treat this like an ordinary assignment.
|
2014-05-27 07:15:35 +00:00
|
|
|
return Assign(aStr.Data(), aStr.Length(), fallible_t());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!Assign(aTuple, fallible_t())) {
|
|
|
|
NS_ABORT_OOM(aTuple.Length());
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Assign(const substring_tuple_type& aTuple,
|
|
|
|
const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aTuple.IsDependentOn(mData, mData + mLength)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// take advantage of sharing here...
|
2014-05-27 07:15:35 +00:00
|
|
|
return Assign(string_type(aTuple), fallible_t());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type length = aTuple.Length();
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// don't use ReplacePrep here because it changes the length
|
|
|
|
char_type* oldData;
|
|
|
|
uint32_t oldFlags;
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!MutatePrep(length, &oldData, &oldFlags)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2009-03-04 09:50:22 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (oldData) {
|
2014-05-05 17:30:46 +00:00
|
|
|
::ReleaseData(oldData, oldFlags);
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
aTuple.WriteTo(mData, length);
|
2014-05-05 17:30:46 +00:00
|
|
|
mData[length] = 0;
|
|
|
|
mLength = length;
|
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Adopt(char_type* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aData) {
|
2014-05-05 17:30:46 +00:00
|
|
|
::ReleaseData(mData, mFlags);
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aLength == size_type(-1)) {
|
|
|
|
aLength = char_traits::length(aData);
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
mData = aData;
|
|
|
|
mLength = aLength;
|
2014-05-05 17:30:46 +00:00
|
|
|
SetDataFlags(F_TERMINATED | F_OWNED);
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
STRING_STAT_INCREMENT(Adopt);
|
2006-05-12 03:36:37 +00:00
|
|
|
#ifdef NS_BUILD_REFCNT_LOGGING
|
2014-05-05 17:30:46 +00:00
|
|
|
// Treat this as construction of a "StringAdopt" object for leak
|
|
|
|
// tracking purposes.
|
|
|
|
NS_LogCtor(mData, "StringAdopt", 1);
|
2006-05-12 03:36:37 +00:00
|
|
|
#endif // NS_BUILD_REFCNT_LOGGING
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2014-05-05 17:30:46 +00:00
|
|
|
SetIsVoid(true);
|
|
|
|
}
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// This version of Replace is optimized for single-character replacement.
|
2005-10-17 16:28:21 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
|
|
|
char_type aChar)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
aCutStart = XPCOM_MIN(aCutStart, Length());
|
2005-10-17 16:28:21 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (ReplacePrep(aCutStart, aCutLength, 1)) {
|
|
|
|
mData[aCutStart] = aChar;
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2005-10-17 16:28:21 +00:00
|
|
|
|
2014-03-19 17:05:02 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
|
|
|
char_type aChar,
|
|
|
|
const mozilla::fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
aCutStart = XPCOM_MIN(aCutStart, Length());
|
2014-03-19 17:05:02 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!ReplacePrep(aCutStart, aCutLength, 1)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2014-03-19 17:05:02 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
mData[aCutStart] = aChar;
|
2014-03-19 17:05:02 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2005-10-17 16:28:21 +00:00
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
|
|
|
const char_type* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!Replace(aCutStart, aCutLength, aData, aLength,
|
|
|
|
mozilla::fallible_t())) {
|
|
|
|
NS_ABORT_OOM(Length() - aCutLength + 1);
|
2014-03-19 17:05:02 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2014-03-19 17:05:02 +00:00
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
|
|
|
const char_type* aData, size_type aLength,
|
|
|
|
const mozilla::fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// unfortunately, some callers pass null :-(
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!aData) {
|
|
|
|
aLength = 0;
|
|
|
|
} else {
|
|
|
|
if (aLength == size_type(-1)) {
|
|
|
|
aLength = char_traits::length(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsDependentOn(aData, aData + aLength)) {
|
|
|
|
nsTAutoString_CharT temp(aData, aLength);
|
|
|
|
return Replace(aCutStart, aCutLength, temp, mozilla::fallible_t());
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-08 22:30:11 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
aCutStart = XPCOM_MIN(aCutStart, Length());
|
2014-03-19 17:05:02 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
bool ok = ReplacePrep(aCutStart, aCutLength, aLength);
|
|
|
|
if (!ok) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2014-03-19 17:05:02 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aLength > 0) {
|
|
|
|
char_traits::copy(mData + aCutStart, aData, aLength);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2004-06-06 02:17:00 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::ReplaceASCII(index_type aCutStart, size_type aCutLength,
|
|
|
|
const char* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aLength == size_type(-1)) {
|
|
|
|
aLength = strlen(aData);
|
|
|
|
}
|
2014-03-19 17:05:02 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// A Unicode string can't depend on an ASCII string buffer,
|
|
|
|
// so this dependence check only applies to CStrings.
|
2004-06-06 02:17:00 +00:00
|
|
|
#ifdef CharT_is_char
|
2014-05-27 07:15:35 +00:00
|
|
|
if (IsDependentOn(aData, aData + aLength)) {
|
|
|
|
nsTAutoString_CharT temp(aData, aLength);
|
|
|
|
Replace(aCutStart, aCutLength, temp);
|
2014-05-05 17:30:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
aCutStart = XPCOM_MIN(aCutStart, Length());
|
2004-06-08 22:30:11 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (ReplacePrep(aCutStart, aCutLength, aLength) && aLength > 0) {
|
|
|
|
char_traits::copyASCII(mData + aCutStart, aData, aLength);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Replace(index_type aCutStart, size_type aCutLength,
|
|
|
|
const substring_tuple_type& aTuple)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aTuple.IsDependentOn(mData, mData + mLength)) {
|
|
|
|
nsTAutoString_CharT temp(aTuple);
|
|
|
|
Replace(aCutStart, aCutLength, temp);
|
2014-05-05 17:30:46 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type length = aTuple.Length();
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
aCutStart = XPCOM_MIN(aCutStart, Length());
|
2004-06-08 22:30:11 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (ReplacePrep(aCutStart, aCutLength, length) && length > 0) {
|
|
|
|
aTuple.WriteTo(mData + aCutStart, length);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-01-08 20:51:38 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::ReplaceLiteral(index_type aCutStart, size_type aCutLength,
|
|
|
|
const char_type* aData, size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
aCutStart = XPCOM_MIN(aCutStart, Length());
|
2014-01-08 20:51:38 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!aCutStart && aCutLength == Length()) {
|
|
|
|
AssignLiteral(aData, aLength);
|
|
|
|
} else if (ReplacePrep(aCutStart, aCutLength, aLength) && aLength > 0) {
|
|
|
|
char_traits::copy(mData + aCutStart, aData, aLength);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2014-01-08 20:51:38 +00:00
|
|
|
|
2012-05-08 16:42:27 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::SetCapacity(size_type aCapacity)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!SetCapacity(aCapacity, fallible_t())) {
|
|
|
|
NS_ABORT_OOM(aCapacity);
|
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::SetCapacity(size_type aCapacity, const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// capacity does not include room for the terminating null char
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// if our capacity is reduced to zero, then free our buffer.
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aCapacity == 0) {
|
2014-05-05 17:30:46 +00:00
|
|
|
::ReleaseData(mData, mFlags);
|
|
|
|
mData = char_traits::sEmptyBuffer;
|
|
|
|
mLength = 0;
|
|
|
|
SetDataFlags(F_TERMINATED);
|
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
char_type* oldData;
|
|
|
|
uint32_t oldFlags;
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!MutatePrep(aCapacity, &oldData, &oldFlags)) {
|
|
|
|
return false; // out-of-memory
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// compute new string length
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type newLen = XPCOM_MIN(mLength, aCapacity);
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (oldData) {
|
2014-05-05 17:30:46 +00:00
|
|
|
// preserve old data
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mLength > 0) {
|
2014-05-05 17:30:46 +00:00
|
|
|
char_traits::copy(mData, oldData, newLen);
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
::ReleaseData(oldData, oldFlags);
|
|
|
|
}
|
2009-11-19 01:14:29 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// adjust mLength if our buffer shrunk down in size
|
2014-05-27 07:15:35 +00:00
|
|
|
if (newLen < mLength) {
|
2014-05-05 17:30:46 +00:00
|
|
|
mLength = newLen;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// always null-terminate here, even if the buffer got longer. this is
|
|
|
|
// for backwards compat with the old string implementation.
|
2014-05-27 07:15:35 +00:00
|
|
|
mData[aCapacity] = char_type(0);
|
2012-05-08 16:42:27 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2012-05-08 16:42:27 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::SetLength(size_type aLength)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
SetCapacity(aLength);
|
|
|
|
mLength = aLength;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2012-05-08 16:42:27 +00:00
|
|
|
|
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::SetLength(size_type aLength, const fallible_t&)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!SetCapacity(aLength, fallible_t())) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return false;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2012-03-20 18:02:38 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
mLength = aLength;
|
2014-05-05 17:30:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::SetIsVoid(bool aVal)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aVal) {
|
2014-05-05 17:30:46 +00:00
|
|
|
Truncate();
|
|
|
|
mFlags |= F_VOIDED;
|
2014-05-27 07:15:35 +00:00
|
|
|
} else {
|
2014-05-05 17:30:46 +00:00
|
|
|
mFlags &= ~F_VOIDED;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Equals(const self_type& aStr) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return mLength == aStr.mLength &&
|
|
|
|
char_traits::compare(mData, aStr.mData, mLength) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Equals(const self_type& aStr,
|
|
|
|
const comparator_type& aComp) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return mLength == aStr.mLength &&
|
|
|
|
aComp(mData, aStr.mData, mLength, aStr.mLength) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Equals(const char_type* aData) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// unfortunately, some callers pass null :-(
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!aData) {
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_NOTREACHED("null data pointer");
|
|
|
|
return mLength == 0;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// XXX avoid length calculation?
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type length = char_traits::length(aData);
|
|
|
|
return mLength == length &&
|
|
|
|
char_traits::compare(mData, aData, mLength) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::Equals(const char_type* aData,
|
|
|
|
const comparator_type& aComp) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
// unfortunately, some callers pass null :-(
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!aData) {
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_NOTREACHED("null data pointer");
|
|
|
|
return mLength == 0;
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// XXX avoid length calculation?
|
2014-05-27 07:15:35 +00:00
|
|
|
size_type length = char_traits::length(aData);
|
|
|
|
return mLength == length && aComp(mData, aData, mLength, length) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::EqualsASCII(const char* aData, size_type aLen) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return mLength == aLen &&
|
|
|
|
char_traits::compareASCII(mData, aData, aLen) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-04-24 22:02:22 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::EqualsASCII(const char* aData) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return char_traits::compareASCIINullTerminated(mData, mLength, aData) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-04-30 12:05:14 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::LowerCaseEqualsASCII(const char* aData,
|
|
|
|
size_type aLen) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return mLength == aLen &&
|
|
|
|
char_traits::compareLowerCaseToASCII(mData, aData, aLen) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::LowerCaseEqualsASCII(const char* aData) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return char_traits::compareLowerCaseToASCIINullTerminated(mData,
|
|
|
|
mLength,
|
|
|
|
aData) == 0;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-06-06 02:17:00 +00:00
|
|
|
|
2004-02-19 02:44:03 +00:00
|
|
|
nsTSubstring_CharT::size_type
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::CountChar(char_type aChar) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
const char_type* start = mData;
|
|
|
|
const char_type* end = mData + mLength;
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
return NS_COUNT(start, end, aChar);
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::FindChar(char_type aChar, index_type aOffset) const
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aOffset < mLength) {
|
|
|
|
const char_type* result = char_traits::find(mData + aOffset,
|
|
|
|
mLength - aOffset, aChar);
|
|
|
|
if (result) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return result - mData;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-02-19 02:44:03 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-11-25 07:03:20 +00:00
|
|
|
|
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::StripChar(char_type aChar, int32_t aOffset)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (mLength == 0 || aOffset >= int32_t(mLength)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-11-25 07:03:20 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!EnsureMutable()) { // XXX do this lazily?
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_ABORT_OOM(mLength);
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-11-25 07:03:20 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// XXX(darin): this code should defer writing until necessary.
|
2004-11-25 07:03:20 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
char_type* to = mData + aOffset;
|
|
|
|
char_type* from = mData + aOffset;
|
|
|
|
char_type* end = mData + mLength;
|
2004-11-25 07:03:20 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
while (from < end) {
|
2014-05-05 17:30:46 +00:00
|
|
|
char_type theChar = *from++;
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aChar != theChar) {
|
2014-05-05 17:30:46 +00:00
|
|
|
*to++ = theChar;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2004-11-25 07:03:20 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
*to = char_type(0); // add the null
|
|
|
|
mLength = to - mData;
|
|
|
|
}
|
2009-11-04 21:33:23 +00:00
|
|
|
|
2010-07-21 00:11:19 +00:00
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::StripChars(const char_type* aChars, uint32_t aOffset)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aOffset >= uint32_t(mLength)) {
|
2014-05-05 17:30:46 +00:00
|
|
|
return;
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!EnsureMutable()) { // XXX do this lazily?
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_ABORT_OOM(mLength);
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// XXX(darin): this code should defer writing until necessary.
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
char_type* to = mData + aOffset;
|
|
|
|
char_type* from = mData + aOffset;
|
|
|
|
char_type* end = mData + mLength;
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
while (from < end) {
|
2014-05-05 17:30:46 +00:00
|
|
|
char_type theChar = *from++;
|
|
|
|
const char_type* test = aChars;
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
for (; *test && *test != theChar; ++test);
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
if (!*test) {
|
|
|
|
// Not stripped, copy this char.
|
|
|
|
*to++ = theChar;
|
|
|
|
}
|
2010-07-21 00:11:19 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
*to = char_type(0); // add the null
|
|
|
|
mLength = to - mData;
|
|
|
|
}
|
2010-07-21 00:11:19 +00:00
|
|
|
|
2012-08-09 07:09:40 +00:00
|
|
|
int
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::AppendFunc(void* aArg, const char* aStr, uint32_t aLen)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
self_type* self = static_cast<self_type*>(aArg);
|
2012-04-13 16:58:59 +00:00
|
|
|
|
2014-05-05 17:30:46 +00:00
|
|
|
// NSPR sends us the final null terminator even though we don't want it
|
2014-05-27 07:15:35 +00:00
|
|
|
if (aLen && aStr[aLen - 1] == '\0') {
|
|
|
|
--aLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2012-04-13 16:58:59 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
self->AppendASCII(aStr, aLen);
|
2012-04-13 16:58:59 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
return aLen;
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2010-11-30 18:18:15 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
void
|
|
|
|
nsTSubstring_CharT::AppendPrintf(const char* aFormat, ...)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
2014-05-27 07:15:35 +00:00
|
|
|
va_start(ap, aFormat);
|
|
|
|
uint32_t r = PR_vsxprintf(AppendFunc, this, aFormat, ap);
|
|
|
|
if (r == (uint32_t)-1) {
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_RUNTIMEABORT("Allocation or other failure in PR_vsxprintf");
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
2011-08-25 14:43:49 +00:00
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
void
|
|
|
|
nsTSubstring_CharT::AppendPrintf(const char* aFormat, va_list aAp)
|
2014-05-05 17:30:46 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
uint32_t r = PR_vsxprintf(AppendFunc, this, aFormat, aAp);
|
|
|
|
if (r == (uint32_t)-1) {
|
2014-05-05 17:30:46 +00:00
|
|
|
NS_RUNTIMEABORT("Allocation or other failure in PR_vsxprintf");
|
2014-05-27 07:15:35 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
}
|
2010-11-30 18:18:15 +00:00
|
|
|
|
2013-09-24 17:36:55 +00:00
|
|
|
/* hack to make sure we define FormatWithoutTrailingZeros only once */
|
2010-11-30 18:18:15 +00:00
|
|
|
#ifdef CharT_is_PRUnichar
|
2014-05-27 07:15:35 +00:00
|
|
|
// Returns the length of the formatted aDouble in aBuf.
|
2013-09-24 17:36:55 +00:00
|
|
|
static int
|
2014-05-27 07:15:35 +00:00
|
|
|
FormatWithoutTrailingZeros(char (&aBuf)[40], double aDouble,
|
|
|
|
int aPrecision)
|
2010-11-30 18:18:15 +00:00
|
|
|
{
|
2013-09-24 17:36:55 +00:00
|
|
|
static const DoubleToStringConverter converter(DoubleToStringConverter::UNIQUE_ZERO |
|
|
|
|
DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN,
|
|
|
|
"Infinity",
|
|
|
|
"NaN",
|
|
|
|
'e',
|
|
|
|
-6, 21,
|
|
|
|
6, 1);
|
2014-05-27 07:15:35 +00:00
|
|
|
double_conversion::StringBuilder builder(aBuf, sizeof(aBuf));
|
2013-09-24 17:36:55 +00:00
|
|
|
bool exponential_notation = false;
|
2014-05-27 07:15:35 +00:00
|
|
|
converter.ToPrecision(aDouble, aPrecision, &exponential_notation, &builder);
|
2013-09-24 17:36:55 +00:00
|
|
|
int length = builder.position();
|
|
|
|
char* formattedDouble = builder.Finalize();
|
|
|
|
|
2014-05-27 07:15:35 +00:00
|
|
|
// If we have a shorter string than aPrecision, it means we have a special
|
2013-09-24 17:36:55 +00:00
|
|
|
// value (NaN or Infinity). All other numbers will be formatted with at
|
2014-05-27 07:15:35 +00:00
|
|
|
// least aPrecision digits.
|
|
|
|
if (length <= aPrecision) {
|
2013-09-24 17:36:55 +00:00
|
|
|
return length;
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
2014-05-05 17:30:46 +00:00
|
|
|
|
2013-09-24 17:36:55 +00:00
|
|
|
char* end = formattedDouble + length;
|
2014-05-27 07:15:35 +00:00
|
|
|
char* decimalPoint = strchr(aBuf, '.');
|
2013-09-24 17:36:55 +00:00
|
|
|
// No trailing zeros to remove.
|
2014-05-27 07:15:35 +00:00
|
|
|
if (!decimalPoint) {
|
2013-09-24 17:36:55 +00:00
|
|
|
return length;
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 17:36:55 +00:00
|
|
|
if (MOZ_UNLIKELY(exponential_notation)) {
|
|
|
|
// We need to check for cases like 1.00000e-10 (yes, this is
|
|
|
|
// disgusting).
|
|
|
|
char* exponent = end - 1;
|
2014-05-27 07:15:35 +00:00
|
|
|
for (; ; --exponent) {
|
2013-09-24 17:36:55 +00:00
|
|
|
if (*exponent == 'e') {
|
|
|
|
break;
|
|
|
|
}
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
2013-09-24 17:36:55 +00:00
|
|
|
char* zerosBeforeExponent = exponent - 1;
|
2014-05-27 07:15:35 +00:00
|
|
|
for (; zerosBeforeExponent != decimalPoint; --zerosBeforeExponent) {
|
2013-09-24 17:36:55 +00:00
|
|
|
if (*zerosBeforeExponent != '0') {
|
|
|
|
break;
|
|
|
|
}
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
2013-09-24 17:36:55 +00:00
|
|
|
if (zerosBeforeExponent == decimalPoint) {
|
|
|
|
--zerosBeforeExponent;
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
2013-09-24 17:36:55 +00:00
|
|
|
// Slide the exponent to the left over the trailing zeros. Don't
|
|
|
|
// worry about copying the trailing NUL character.
|
|
|
|
size_t exponentSize = end - exponent;
|
|
|
|
memmove(zerosBeforeExponent + 1, exponent, exponentSize);
|
|
|
|
length -= exponent - (zerosBeforeExponent + 1);
|
|
|
|
} else {
|
|
|
|
char* trailingZeros = end - 1;
|
2014-05-27 07:15:35 +00:00
|
|
|
for (; trailingZeros != decimalPoint; --trailingZeros) {
|
2013-09-24 17:36:55 +00:00
|
|
|
if (*trailingZeros != '0') {
|
|
|
|
break;
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-24 17:36:55 +00:00
|
|
|
if (trailingZeros == decimalPoint) {
|
|
|
|
--trailingZeros;
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
2013-09-24 17:36:55 +00:00
|
|
|
length -= end - (trailingZeros + 1);
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 17:36:55 +00:00
|
|
|
return length;
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
|
|
|
#endif /* CharT_is_PRUnichar */
|
|
|
|
|
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::AppendFloat(float aFloat)
|
2013-09-24 17:36:55 +00:00
|
|
|
{
|
|
|
|
char buf[40];
|
|
|
|
int length = FormatWithoutTrailingZeros(buf, aFloat, 6);
|
|
|
|
AppendASCII(buf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-05-27 07:15:35 +00:00
|
|
|
nsTSubstring_CharT::AppendFloat(double aFloat)
|
2010-11-30 18:18:15 +00:00
|
|
|
{
|
|
|
|
char buf[40];
|
2013-09-24 17:36:55 +00:00
|
|
|
int length = FormatWithoutTrailingZeros(buf, aFloat, 15);
|
|
|
|
AppendASCII(buf, length);
|
2010-11-30 18:18:15 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 03:16:41 +00:00
|
|
|
size_t
|
|
|
|
nsTSubstring_CharT::SizeOfExcludingThisMustBeUnshared(
|
2014-05-27 07:15:35 +00:00
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-20 03:16:41 +00:00
|
|
|
{
|
|
|
|
if (mFlags & F_SHARED) {
|
|
|
|
return nsStringBuffer::FromData(mData)->
|
2014-05-27 07:15:35 +00:00
|
|
|
SizeOfIncludingThisMustBeUnshared(aMallocSizeOf);
|
2013-01-18 05:21:35 +00:00
|
|
|
}
|
2012-02-20 03:16:41 +00:00
|
|
|
if (mFlags & F_OWNED) {
|
2014-05-27 07:15:35 +00:00
|
|
|
return aMallocSizeOf(mData);
|
2012-02-20 03:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach here, exactly one of the following must be true:
|
|
|
|
// - F_VOIDED is set, and mData points to sEmptyBuffer;
|
|
|
|
// - F_FIXED is set, and mData points to a buffer within a string
|
|
|
|
// object (e.g. nsAutoString);
|
|
|
|
// - None of F_SHARED, F_OWNED, F_FIXED is set, and mData points to a buffer
|
|
|
|
// owned by something else.
|
|
|
|
//
|
|
|
|
// In all three cases, we don't measure it.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
nsTSubstring_CharT::SizeOfExcludingThisIfUnshared(
|
2014-05-27 07:15:35 +00:00
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-20 03:16:41 +00:00
|
|
|
{
|
|
|
|
// This is identical to SizeOfExcludingThisMustBeUnshared except for the
|
|
|
|
// F_SHARED case.
|
|
|
|
if (mFlags & F_SHARED) {
|
|
|
|
return nsStringBuffer::FromData(mData)->
|
2014-05-27 07:15:35 +00:00
|
|
|
SizeOfIncludingThisIfUnshared(aMallocSizeOf);
|
2012-02-20 03:16:41 +00:00
|
|
|
}
|
|
|
|
if (mFlags & F_OWNED) {
|
2014-05-27 07:15:35 +00:00
|
|
|
return aMallocSizeOf(mData);
|
2012-02-20 03:16:41 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-18 05:21:35 +00:00
|
|
|
size_t
|
|
|
|
nsTSubstring_CharT::SizeOfExcludingThisEvenIfShared(
|
2014-05-27 07:15:35 +00:00
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
2013-01-18 05:21:35 +00:00
|
|
|
{
|
|
|
|
// This is identical to SizeOfExcludingThisMustBeUnshared except for the
|
|
|
|
// F_SHARED case.
|
|
|
|
if (mFlags & F_SHARED) {
|
|
|
|
return nsStringBuffer::FromData(mData)->
|
2014-05-27 07:15:35 +00:00
|
|
|
SizeOfIncludingThisEvenIfShared(aMallocSizeOf);
|
2013-01-18 05:21:35 +00:00
|
|
|
}
|
|
|
|
if (mFlags & F_OWNED) {
|
2014-05-27 07:15:35 +00:00
|
|
|
return aMallocSizeOf(mData);
|
2013-01-18 05:21:35 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-20 03:16:41 +00:00
|
|
|
size_t
|
|
|
|
nsTSubstring_CharT::SizeOfIncludingThisMustBeUnshared(
|
2014-05-27 07:15:35 +00:00
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-20 03:16:41 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return aMallocSizeOf(this) +
|
|
|
|
SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
|
2012-02-20 03:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
|
|
|
nsTSubstring_CharT::SizeOfIncludingThisIfUnshared(
|
2014-05-27 07:15:35 +00:00
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
2012-02-20 03:16:41 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
2012-02-20 03:16:41 +00:00
|
|
|
}
|
|
|
|
|
2013-01-18 05:21:35 +00:00
|
|
|
size_t
|
|
|
|
nsTSubstring_CharT::SizeOfIncludingThisEvenIfShared(
|
2014-05-27 07:15:35 +00:00
|
|
|
mozilla::MallocSizeOf aMallocSizeOf) const
|
2013-01-18 05:21:35 +00:00
|
|
|
{
|
2014-05-27 07:15:35 +00:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThisEvenIfShared(aMallocSizeOf);
|
2013-01-18 05:21:35 +00:00
|
|
|
}
|
|
|
|
|